ul列表中的li宽度怎么设置css样式,让其能与内容宽度实现自适应?

li中文字过多会出现滚动条,想实现li宽与文字长度自适应,css样式有能解决的方法吗?换了好几种方式都不行,没能解决

li不设置 宽度 呢

width设置为max-content

外层元素设置了overflow: auto;属性吧
这个还是得看css样式,才好处理

这是ul的样式:
element.style {
font-family: "Microsoft YaHei";
font-size: 14.67px;
}
.ztree {
margin: 0;
padding: 5px;
}

  • {
    box-sizing: border-box;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    }
    用户代理样式表
    ul {
    display: block;
    list-style-type: disc;
    margin-block-start: 1em;
    margin-block-end: 1em;
    margin-inline-start: 0px;
    margin-inline-end: 0px;
    padding-inline-start: 40px;
    }
    .simplebar-content {
    direction: inherit;
    box-sizing: border-box !important;
    position: relative;
    display: block;
    height: 100%;
    width: auto;
    visibility: visible;
    overflow: scroll;
    max-width: 100%;
    max-height: 100%;
    }
    .simplebar-offset {
    direction: inherit !important;
    box-sizing: inherit !important;
    resize: none !important;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    padding: 0;
    margin: 0;
    -webkit-overflow-scrolling: touch;
    }
    .simplebar-mask {
    direction: inherit;
    position: absolute;
    overflow: hidden;
    padding: 0;
    margin: 0;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    width: auto !important;
    height: auto !important;
    z-index: 0;
    };

这是li样式:
element.style {
line-height: 23px;
}
.ztree li {
padding: 0;
margin: 0;
list-style: none;
text-align: left;
white-space: nowrap;
outline: 0;
}
.ztree * {
padding: 0;
margin: 0;
}

  • {
    box-sizing: border-box;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    }
    用户代理样式表
    li {
    display: list-item;
    text-align: -webkit-match-parent;
    }
    样式属性 {
    font-family: "Microsoft YaHei";
    font-size: 14.67px;
    }
    用户代理样式表
    ul {
    list-style-type: disc;
    }
    .simplebar-content {
    direction: inherit;
    box-sizing: border-box !important;
    position: relative;
    display: block;
    height: 100%;
    width: auto;
    visibility: visible;
    overflow: scroll;
    max-width: 100%;
    max-height: 100%;
    }
    .simplebar-offset {
    direction: inherit !important;
    box-sizing: inherit !important;
    resize: none !important;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    padding: 0;
    margin: 0;
    -webkit-overflow-scrolling: touch;
    }
    .simplebar-mask {
    direction: inherit;
    position: absolute;
    overflow: hidden;
    padding: 0;
    margin: 0;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    width: auto !important;
    height: auto !important;
    z-index: 0;
    }

看的有点懵

img


这里设置了滚动条,去掉试试,
不行的话,可以把完整的代码发出来,我帮你调试一下