【发布时间】:2021-02-04 05:30:30
【问题描述】:
我有一个简单的有序列表。我使用 counter-reset 属性来更改数字的样式。但问题是当容器 (.list) 宽度较小时,列表不会像有序列表那样直接对齐。
.list{
border: 1px solid black;
width: 40%;
box-sizing: border-box;
}
ol{
list-style: none;
counter-reset: csscounter;
padding-left: 0.5rem;
}
li{
counter-increment:csscounter;
margin-bottom: 0.25rem;
}
li:before{
content: counter(csscounter);
background: gray;
width: 1.5rem;
height: 1.5rem;
border-radius: 100%;
display: inline-block;
line-height: 1.5rem;
text-align: center;
color: white;
margin-right: 0.5rem;
}
<div class='list'>
<ol>
<li>
Enter your mobile number to view your book collection
</li>
<li>
Select the books that you want to add to your collection
</li>
<li>
Confirm and Submit
</li>
</ol>
</div>
如果我删除 <ol> 的 css 属性,列表将正确呈现并且不会出现对齐问题。
.list{
border: 1px solid black;
width: 40%;
box-sizing: border-box;
}
<div class='list'>
<ol>
<li>
Enter your mobile number to view your book collection
</li>
<li>
Select the books that you want to add to your collection
</li>
<li>
Confirm and Submit
</li>
</ol>
</div>
【问题讨论】:
标签: css html-lists text-align