3

I would like to create lists like these using HTML5 and CSS only:

1 First
  1.1 Indent 1
  1.2 Indent 2
2 Second
  2.1 Indent 1
  2.2 Indent 2
    2.2.1 More depth

I've checked multiple tutorials on ordered lists but it seems that the <ol> tag does not have the option to do so. Is it possible using HTML5 and CSS?

Adam Arold
  • 27,872
  • 21
  • 103
  • 189
  • Is the automatic numbering of those list what your question is actually about? If so, check https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Counters – CBroe Sep 04 '14 at 14:45
  • See http://stackoverflow.com/questions/2729927/number-nested-ordered-lists-in-html – Aibrean Sep 04 '14 at 14:45

1 Answers1

5

You can use before pseudo-element to achieve that:

html

<ul class="numeric">
<li>First
    <ul>
        <li>Indent </li>
        <li>Indent </li>
    </ul>
</li>
<li>Second
    <ul>
        <li>Indent</li>
        <li>Indent</li>
    </ul>
</li>
<li>Third
        <ul>
            <li>Indent</li>
            <li>Indent</li>
            <li>Indent</li>
            <li>Indent</li>
        </ul>
    </li>
<li>Fourth
    <ul>
        <li>Indent</li>
        <li>Indent</li>
    </ul>
</li>
<li>Five</li>

css

ul.numeric { counter-reset:section; list-style-type:none; }
ul.numeric li { list-style-type:none; }
ul.numeric li ul { counter-reset:subsection; }
ul.numeric li:before{
    counter-increment:section;
    content:counter(section) ". ";
}
ul.numeric li ul li:before {
    counter-increment:subsection;
    content:counter(section) "." counter(subsection) " ";
}

fiddle

References:

CSS counter-reset Property

Alex Char
  • 32,295
  • 8
  • 49
  • 69