我真的不知道你想达到什么目标,为什么你需要在.nested-list
那里上课。无论如何,我把她的两个解决方法都可以解决你的问题。
第一:没有任何类
这将为所有列表添加顺序编号
ol {
counter-reset: section;
list-style-type: none;
}
li::before {
counter-increment: section;
content: counters(section,".") " ";
}
注意:在您的代码中,您有ol>li
但没有必要添加直接育儿,因为<li>
只能存在于您的内部,<ol>
所以我减少了您的代码。
ol {
counter-reset: section;
list-style-type: none;
}
li::before {
counter-increment: section;
content: counters(section,".") " ";
}
<ol>
<li>Entry</li>
<li>Entry with subentries
<ol class="nested-list">
<li>Entry</li>
<li>Entry with subentries
<ol>
<li>Entry</li>
<li>Entry</li>
</ol>
</li>
<li>Entry</li>
</ol>
</li>
<li>Entry</li>
<li>Entry with subentries
<ol class="nested-list">
<li>Entry</li>
<li>Entry</li>
</ol>
</li>
</ol>
第二: .nested-list Workarround
您可以“隐藏”所有::before
内容并“取消隐藏”第一级,ol.nested-list
如果您删除直接>
育儿,您可以在里面的所有子列表中拥有这种列表.nested-li
ol {
counter-reset: section;
list-style-type: none;
}
li::before {
counter-increment: section;
content: counters(section,".") " ";
visibility: hidden;
}
.nested-list > li::before{
visibility: visible;
}
例子:
ol {
counter-reset: section;
list-style-type: none;
}
li::before {
counter-increment: section;
content: counters(section,".") " ";
visibility: hidden;
}
.nested-list > li::before{
visibility: visible;
}
<ol>
<li>Entry</li>
<li>Entry with subentries
<ol class="nested-list">
<li>Entry</li>
<li>Entry with subentries
<ol>
<li>Entry</li>
<li>Entry</li>
</ol>
</li>
<li>Entry</li>
</ol>
</li>
<li>Entry</li>
<li>Entry with subentries
<ol class="nested-list">
<li>Entry</li>
<li>Entry</li>
</ol>
</li>
</ol>
注意:为了使用,::before
最好::after
添加两个克隆::