简体   繁体   English

CSS“反增量”不递增

[英]CSS “counter-increment” not incrementing

Following this tutorial , I am trying to style my list item counters in an <ol> . 在学习完本教程之后 ,我试图在<ol>列表项计数器的样式。 However, my counters are not incrementing. 但是,我的计数器没有增加。

 .prog-ol ol { counter-reset:li; margin-left:0; padding-left:0; } .prog-ol li { position:relative; /* Create a positioning context */ margin:0 0 6px 2em; /* Give each list item a left margin to make room for the numbers */ padding:4px 8px; /* Add some spacing around the content */ list-style:none; /* Disable the normal item numbering */ } .prog-ol li:before { content:counter(li); /* Use the counter as content */ counter-increment:li; /* Increment the counter by 1 */ /* Position and style the number */ position:absolute; top:-2px; left:-2em; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; box-sizing:border-box; width:2em; /* Some space between the number and the content in browsers that support generated content but not positioning it (Camino 2 is one example) */ margin-right:8px; padding:4px; border-top:2px solid #666; color:#fff; background:#666; font-weight:bold; font-family:"Helvetica Neue", Arial, sans-serif; text-align:center; } 
  <ol class="prog-ol"> <li>Foo</li> <li>Bar</li> <li>baz</li> </ol> 

It seems like these two lines should pretty much take care of it: 似乎这两行应该好好处理:

content:counter(li); /* Use the counter as content */
counter-increment:li; /* Increment the counter by 1 */

Why aren't my counters incrementing? 为什么我的计数器不增加?

You are defining your counter on .prog-ol ol which are the <ol> descendants of the element that is a member of the prog-ol class. 您正在.prog-ol ol上定义计数器,它们是prog-ol类成员的元素的<ol>后代。

Remove the ol from the selector. 从选择器中删除ol

 .prog-ol { counter-reset:li; margin-left:0; padding-left:0; } .prog-ol li { position:relative; /* Create a positioning context */ margin:0 0 6px 2em; /* Give each list item a left margin to make room for the numbers */ padding:4px 8px; /* Add some spacing around the content */ list-style:none; /* Disable the normal item numbering */ } .prog-ol li:before { content:counter(li); /* Use the counter as content */ counter-increment:li; /* Increment the counter by 1 */ /* Position and style the number */ position:absolute; top:-2px; left:-2em; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; box-sizing:border-box; width:2em; /* Some space between the number and the content in browsers that support generated content but not positioning it (Camino 2 is one example) */ margin-right:8px; padding:4px; border-top:2px solid #666; color:#fff; background:#666; font-weight:bold; font-family:"Helvetica Neue", Arial, sans-serif; text-align:center; } 
 <ol class="prog-ol"> <li>Foo</li> <li>Bar</li> <li>baz</li> </ol> 

(For that matter, you should probably remove the ol from the class name too. Tying class names to specific elements doesn't make a lot of sense. You can combine them with type selectors if desired). (为此,您可能也应该从类名称中删除ol 。将类名称绑定到特定元素没有多大意义。可以根据需要将它们与类型选择器结合使用)。

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

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