gpt4 book ai didi

html - CSS 计数器 : doesn't reset if there is a wrapper outside OL

转载 作者:行者123 更新时间:2023-11-28 03:10:18 24 4
gpt4 key购买 nike

我尝试使用“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 继续。为什么?即使包裹在容器中,如何重置新计数器?谢谢

最佳答案

给div添加counter reset,给wrapped ol赋一个新值。 fiddle :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,".") " ";
}

关于html - CSS 计数器 : doesn't reset if there is a wrapper outside OL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30869121/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com