html - 自定义嵌套有序列表编号
问题描述
我有嵌套列表,我无法更改其结构。第一个li
元素不能包含在编号中,但是,它的子元素必须全部编号。这是JsFiddle。
ol li ol {
counter-reset: section;
list-style-type: none;
}
ol li ol li::before {
counter-increment: section;
content: counters(section, ".") " ";
}
<ol id="root">
<li>List item two with subitems (this should not be numbered):
<ol id="toc0">
<li>Subitem 1 (This should be numbered 1)</li>
<li>Subitem 2 (This should be 2)</li>
<ol>
<li> subitem (this should be 2.1)</li>
<li> subitem (this should be 2.2)</li>
<ol>
<li> subitem (This should be 2.2.1)</li>
<li> subitem (This should be 2.2.2)</li>
</ol>
</ol>
<li>Subitem 3 (This should be 3)</li>
<li>Subitem 4 (This should be 4)</li>
</ol>
</li>
</ol>
解决方案
您的标记无效,ol
不能是另一个的直接子级ol
。您必须更新 HTML 来修复它,您现有的 CSS 只需稍加编辑即可正常工作。
ol {
list-style: none;
}
ol li ol {
counter-reset: section;
}
ol li ol li::before {
counter-increment: section;
content: counters(section, ".") " ";
}
<ol id="root">
<li>List item two with subitems (this should not be numbered):
<ol id="toc0">
<li>Subitem 1 (This should be numbered 1)</li>
<li>
Subitem 2 (This should be 2)
<ol>
<li>subitem (this should be 2.1)</li>
<li>
subitem (this should be 2.2)
<ol>
<li> subitem (This should be 2.2.1)</li>
<li> subitem (This should be 2.2.2)</li>
</ol>
</li>
</ol>
</li>
<li>Subitem 3 (This should be 3)</li>
<li>Subitem 4 (This should be 4)</li>
</ol>
</li>
</ol>
推荐阅读
- react-native - 如何为 BottomTabBar 反应导航中的每个选项卡使用自定义宽度?
- oracle - ORA-00972: 标识符太长,来自 sath89:oracle-12c:latest 的 oracle 映像
- reactjs - 使用 React Hooks + Fetch API 设置状态不会触发重新渲染
- python - angular js上传文件功能无法按预期工作
- visual-studio-code - 当光标在括号中时vscode没有提示,我该如何解决?
- ruby-on-rails - 查找方法委托给的类?(导轨)
- python - 蟒蛇 | 自动生成 DataFrame
- c# - 奥尔良谷物代码中的反应式扩展
- python-3.x - \resize.cpp:3787: 错误: (-215:Assertion failed) func != 0 in function 'cv::hal::resize'
- reactjs - 当子组件返回新内容时,是否会重新渲染父组件?