Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML/CSS multilevel nested lists numbering [duplicate]

Is there a way to achieve the below numbering using straight HTML and CSS lists (<ul> or <ol>)?

1. Link 1
2. Link 2
3. Link 3
    3.1. Link 3.1
    3.2. Link 3.2
    3.3. Link 3.3
4. Link 4
    4.1. Link 4.1
        4.1.1 Link 4.1.1
        4.1.2 Link 4.1.2
5. Link 5

Thanks in advance!

like image 655
MrUpsidown Avatar asked Feb 20 '14 13:02

MrUpsidown


People also ask

How do you continue numbering in HTML?

If you start a list, then stop to interject some other content, then begin the list again, you could use &lt;ol start="..."&gt; to continue numbering where you left off.

How do you make a nested list in HTML?

Correct: <ul> as child of <li> The proper way to make HTML nested list is with the nested <ul> as a child of the <li> to which it belongs. The nested list should be inside of the <li> element of the list in which it is nested.

What is multilevel list in HTML?

A multilevel list is a list with more than one level. For example, the picture is an example of a multilevel bullet list and a multilevel numbered list. In the multilevel numbered list, there is an "a" and "b" item under 2.


1 Answers

You could use CSS counters:

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

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

Working Demo (also on JSBin):

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

li:before {
  counter-increment: section;
  content: counters(section, ".") ". Link " counters(section, ".") " ";
}
<ol>
  <li></li>
  <li></li>
  <li>
    <ol>
      <li></li>
      <li></li>
      <li></li>
    </ol>
  </li>
  <li>
    <ol>
      <li>    
        <ol>
        <li></li>
        <li></li>
        </ol>
      </li>
    </ol>
  </li>
  <li></li>
</ol>
like image 165
Hashem Qolami Avatar answered Sep 18 '22 19:09

Hashem Qolami