Add "null zero" to the first level of nested css counter

Here's the ordered list I have so far:

1 Item
2 Item
    2.1 Item
    2.2 Item
    2.3 Item
        2.3.1 Item
        2.3.2 Item
        2.3.3 Item
3 Item
4 Item

      

It is created like this:

<ol>
    <li>Item</li>
    <li>Item
    <ol>
        <li>Item</li>
        <li>Item</li>
        <li>Item
        <ol>
            <li>Item</li>
            <li>Item</li>
            <li>Item</li>
        </ol></li>
    </ol></li>
    <li>Item</li>
    <li>Item</li>
</ol>

      

and CSS:

ol {
    counter-reset:section;
    list-style-type: none;
}

li:before {
    counter-increment: section;
    content: counters(section, ".") " ";
}

      

What I want to do is make the top level items of the list "zero point" after the counter, as in

1.0 Item
2.0 Item
    2.1 Item

      

etc. Can this be done in CSS? This may require creative solutions.

+3


source to share


1 answer


Set the start style to include 0

.

ol {
    counter-reset: section;
    list-style-type: none;
}
li:before {
    counter-increment: section;
    content: counters(section, ".")".0 ";
}

      

Overwrite this by selecting children.



li > ol > li:before {
    content: counters(section, ".")" ";
}

      

ol {
    counter-reset: section;
    list-style-type: none;
}
li:before {
    counter-increment: section;
    content: counters(section, ".")".0 ";
}
li > ol > li:before {
    content: counters(section, ".")" ";
}
      

<ol>
    <li>Item</li>
    <li>Item
        <ol>
            <li>Item</li>
            <li>Item</li>
            <li>Item
                <ol>
                    <li>Item</li>
                    <li>Item</li>
                    <li>Item</li>
                </ol>
            </li>
        </ol>
    </li>
    <li>Item</li>
    <li>Item</li>
</ol>
      

Run code


+3


source







All Articles