I am styling an HTML nested ordered list (numbered).
I am trying to achieve same layout as MS Word has usually when you press Tab before the numbered list item. Ex:
1. Item at top
1.1.1.1. Item at middle
2. Item at bottom
For now I have the following CSS which sets 1.0.0.1
for the Item at middle
.
Is there any way to fix that with CSS and without changing the HTML?
ol { counter-reset: itemCounter; padding-left: 0 }
ol li { list-style: none; }
ol li:not(:has(ol)):before {
content: counters(itemCounter, ".") ". ";
counter-increment: itemCounter;
}
<ol>
<li>Item at top</li>
<li>
<ol>
<li>
<ol>
<li>
<ol>
<li>Item at middle</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
<li>Item at bottom</li>
</ol>
2
Answers
With this modification, the nested ol element will start with "1" instead of "0", and the numbering will continue from there.
This seems to work as you need it to: