简体   繁体   English

CSS Counter Increment不起作用

[英]CSS Counter Increment is not working

This is my CSS and HTML: 这是我的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> 

This code is not working. 此代码无效。

 counter-increment: headings 1;  
 content: counter(headings, decimal); 

This inserts 1 every time, what am I missing? 每次插入1 ,我错过了什么?

You should have this css on the ul itself: 你应该在ul本身上有这个css:

.moving-steps {
    counter-reset: headings;
}

and counter-increment should only contain headings : counter-increment应该只包含headings

.moving-steps > li:before {
    counter-increment: headings;
}

Check out this JS Fiddle : 看看这个JS小提琴

 .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> 

Just Add the following style additionally 只需添加以下样式

body{counter-reset: headings;}

then the value will be increment 然后价值将增加

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM