我正在制作一个多列、CSS 编号的 TOC,如下所示:
| 1. TOC Level-1 | 2. TOC Level-1 |
| 1.1 TOC Level-2 | 2.1 TOC Level-2 |
| 1.2 TOC Level-2 | 2.2 TOC Level-2 |
| 1.3 TOC Level-2 | 3. TOC Level-1 |
| 3.1 TOC Level-2 |
由于 CSS 列是不可控的,因此使用 JS 和浮动“列”类进行包装。
这是我遵循的示例: http ://www.2ality.com/2012/01/numbering-headingshtml.html
这是我使用的 CSS:
body {} .column {
border: 2px dotted grey;
float: left;
width: 40%;
}
.menu-item:hover {
cursor: pointer;
color: blue;
}
.sub-nav-content {
counter-reset: toc1;
}
h1 {
counter-reset: toc2;
}
h1:before {
counter-increment: toc1;
content: counter(toc1)". ";
}
h2:before {
counter-increment: toc2;
content: counter(toc1)"." counter(toc2)" ";
}
<div class="sub-nav">
<div class="sub-nav-content">
<div class="column">
<a class="menu-item"><h1>TOC entry level1</h1></a>
<a class="menu-item"><h2>TOC entry level2</h2></a>
<a class="menu-item"><h2>TOC entry level2</h2></a>
<a class="menu-item"><h2>TOC entry level2</h2></a>
</div>
<div class=column>
<a class="menu-item"><h1>TOC entry level1</h1></a>
<a class="menu-item"><h2>TOC entry level2</h2></a>
<a class="menu-item"><h2>TOC entry level2</h2></a>
<a class="menu-item"><h1>TOC entry level1</h1></a>
<a class="menu-item"><h2>TOC entry level2</h2></a>
<a class="menu-item"><h2>TOC entry level2</h2></a>
<a class="menu-item"><h2>TOC entry level2</h2></a>
</div>
</div>
</div>
不知何故,我无法让 Level-2 计数器增加。