我找到了一些与此问题相关的主题,但没有一个对我有帮助。
ol {
list-style: none;
padding: 0;
margin: 0;
counter-reset: my-awesome-counter;
columns: 2;
-webkit-columns: 2;
-moz-columns: 2;
}
ol li {
counter-increment: my-awesome-counter;
margin: 1rem 0.25rem;
line-height: normal;
}
ol li:before {
display: inline-block;
content: counter(my-awesome-counter);
width: 40px;
height: 40px;
line-height: 24px;
background: #000;
border-radius: 25px;
color: white;
text-align: center;
margin-right: 0.5rem;
font-size: 24px;
font-weight: 700;
}
我错过了什么?
最佳答案
尝试使用 position:absolute;
对于伪元素并给出 padding-left
至 <li>
查看更新的代码段:
ol {
list-style: none;
padding: 0;
margin: 0;
counter-reset: my-awesome-counter;
/*columns: 2;
-webkit-columns: 2;
-moz-columns: 2;
*/
width: 300px;
}
ol li {
counter-increment: my-awesome-counter;
margin: 1rem 0.25rem;
line-height: normal;
padding-left: 60px;
position: relative;
}
ol li:before {
display: inline-block;
content: counter(my-awesome-counter);
width: 44px;
height: 40px;
line-height: 24px;
background: #000;
border-radius: 25px;
color: white;
text-align: center;
margin-right: 0.5rem;
font-size: 24px;
font-weight: 700;
position: absolute;
left: 0;
}
<ol>
<li> test test test testtest test test testtest test test testtest test test testtest test test testtest test test test</li>
<li> test test test testtest test test testtest test test testtest test test testtest test test testtest test test test</li>
</ol>
关于html - 自定义 ol li 缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52847458/