Following this tutorial , I am trying to style my list item counters in an <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.
Remove the ol
from the selector.
.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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.