gpt4 book ai didi

html - 保留一个 ol 数和 overflow

转载 作者:太空宇宙 更新时间:2023-11-03 20:24:59 25 4
gpt4 key购买 nike

如果我在有序列表中使用 overflow:hidden,数字会消失,我如何才能保留它们并同时 overflow hidden 的字符?

li {
overflow:hidden;
max-width:70ch
}
<ol>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>Suspendisse venenatis arcu vitae tempor feugiat.</li>
<li>Aenean pellentesque orci eu ligula venenatis sodales.</li>
<li>Praesent sed quam et turpis accumsan luctus.</li>
<li>Nullam sodales nisl eu ultricies convallis</li>
<ol>

最佳答案

设置list-style-position: inside在列表中,这会将数字放在列表项中:

ol {
list-style-position: inside;
}

li {
overflow: hidden;
max-width: 70ch
}
<ol>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing.</li>
<li>Suspendisse venenatis arcu vitae tempor feugiat.</li>
<li>Aenean pellentesque orci eu ligula venenatis.</li>
<li>Praesent sed quam et turpis accumsan luctus.</li>
<li>Nullam sodales nisl eu ultricies convallis</li>
</ol>

另一种解决方案是滚动您自己的 CSS 并使用 CSS 计数器为元素自动编号:

/* counter */
ol {
counter-reset: foo 0;
list-style-type: none;
}
li {
counter-increment: foo 1;
}
li:before {
content: counter(foo) ".";
}
/* position */
li {
padding-left: 2em;
}
li::before {
float: left;
margin-left: -2em;
width: 1.75em;
text-align: right;
}
li {
overflow: hidden;
max-width: 70ch;
}
<ol>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing.</li>
<li>Suspendisse venenatis arcu vitae tempor feugiat.</li>
<li>Aenean pellentesque orci eu ligula venenatis.</li>
<li>Praesent sed quam et turpis accumsan luctus.</li>
<li>Nullam sodales nisl eu ultricies convallis.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing.</li>
<li>Suspendisse venenatis arcu vitae tempor feugiat.</li>
<li>Aenean pellentesque orci eu ligula venenatis.</li>
<li>Praesent sed quam et turpis accumsan luctus.</li>
<li>Nullam sodales nisl eu ultricies convallis. Nullam sodales nisl eu ultricies convallis.</li>
</ol>

关于html - 保留一个 ol 数和 overflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58519541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com