这是我的CSS和HTML:
.moving-steps > li:before {
background: none repeat scroll 0 0 #8F8888;
border-radius: 15px;
color: #FFFFFF;
counter-increment: headings 1;
content: counter(headings, decimal);
display: block;
float: left;
font-size: 16px;
font-weight: bold;
height: 25px;
line-height: 26px;
margin-bottom: 0;
margin-right: 5px;
text-indent: 8px;
width: 25px;
}
<ul class="moving-steps">
<li></li>
<li></li>
<li></li>
</ul>
此代码无效。
counter-increment: headings 1;
content: counter(headings, decimal);
每次都会插入1
,我缺少什么?
答案 0 :(得分:12)
你应该在ul
本身上有这个css:
.moving-steps {
counter-reset: headings;
}
和counter-increment
只应包含headings
:
.moving-steps > li:before {
counter-increment: headings;
}
查看此JS Fiddle:
.moving-steps {
counter-reset: headings;
list-style: none;
}
.moving-steps > li:before {
background: none repeat scroll 0 0 #8F8888;
border-radius: 15px;
color: #FFFFFF;
counter-increment: headings;
content: counter(headings, decimal);
display: block;
float: left;
font-size: 16px;
font-weight: bold;
height: 25px;
line-height: 26px;
margin-bottom: 0;
margin-right: 5px;
text-indent: 8px;
width: 25px;
}
<ul class="moving-steps">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
答案 1 :(得分:1)
另外添加以下样式
body{counter-reset: headings;}
然后值将增加