I recently encountered a problem where I created an ordered list containing over a hundred list items. I setlist-style:decimal-leading-zero;
ol{ list-style: decimal-leading-zero; }
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
...
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
- Some item
Problem:Only the first nine list items have leading zeros.
Expected:Two leading zeros in the first nine list items, and one leading zero in the 10th to 99th list items.
There is no
list-stylefor three decimal places.However, you can use pseudo-selectors andcounters a> to achieve what you want here.
Reference Code:
ol { counter-reset: items; } li { display: block; counter-increment: items; } li:before { content: "00" counter(items)". "; } li:nth-child(n+10):before { content: "0" counter(items)". "; } li:nth-child(n+100):before { content: counter(items)". "; }