To adding number before the toc list, I wrote bellow code.
ul.toc-wrapper {
counter-reset: my-counter 0;
li.toc-item-h2 {
&::before {
counter-increment: my-counter;
content: "0"counter(my-counter)":";
padding-right: 8px;
}
}
li.toc-item-h3 {
...
}
}
<ul class="toc-wrapper">
<li class="toc-item-2">some heading</li>
<li class="toc-item-3">aaaa</li>
<li class="toc-item-3">bbbb</li>
<li class="toc-item-2">hoge heading</li>
<li class="toc-item-3">cccc</li>
<li class="toc-item-3">dddd</li>
...
</ul>
It works fine until number of .toc-item-h2
elements are less than 10.
01: some heading
aaaa
bbbb
02: hoge heading
cccc
dddd
...
09: piyo heading
010: aaaa heading <- I do not want it with 0. should be 10.
Is there any idea to work it without Javascript?
I can use SCSS in this project if needed.
.toc-item-h2
will not be more than 100 .
UPDATE:There are other li
s in same level. So I can not use nth-of-type
/ nth-child
.