我尝试使用“ CSS计数器”创建自定义有序列表(OL
),并以this Mozilla article为例。
我需要稍微修改它,将最后一个OL包装在名为.foo
的DIV包含器中,如此jsFiddle所示。
<div id='foo'>
<ol>
<li>item</li> <!-- 1 -->
<li>item</li> <!-- 2 -->
</ol>
</div>
ol {
counter-reset: section;
list-style-type: none;
}
li::before {
counter-increment: section;
content: counters(section,".") " ";
}
添加包装器,计数器不再重置,数字从4.1和4.2继续。为什么?即使包装在容器内,如何重置新计数器?感谢
答案 0 :(得分:0)
将计数器重置添加到div并为包装的ol分配新值。 小提琴:http://jsfiddle.net/mbmg52sz/3/
ol{
counter-reset: sectionA;
list-style-type: none;
}
li::before {
counter-increment: sectionA;
content: counters(sectionA,".") " ";
}
div{
counter-reset: sectionA;
}
div > ol{
counter-reset: sectionB;
}
div > ol > li{
counter-increment: sectionB;
content: counters(sectionB,".") " ";
}