Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html ordered list 1.1, 1.2 (Nested counters and scope) not working

I use nested counters and scope to create an ordered list:

ol {      counter-reset: item;      padding-left: 10px;  }  li {      display: block  }  li:before {      content: counters(item, ".") " ";      counter-increment: item  }
<ol>      <li>one</li>      <li>two</li>      <ol>          <li>two.one</li>          <li>two.two</li>          <li>two.three</li>      </ol>      <li>three</li>      <ol>          <li>three.one</li>          <li>three.two</li>          <ol>              <li>three.two.one</li>              <li>three.two.two</li>          </ol>      </ol>      <li>four</li>  </ol>

I expect the following outcome:

1. one 2. two   2.1. two.one   2.2. two.two   2.3. two.three 3. three   3.1 three.one   3.2 three.two     3.2.1 three.two.one     3.2.2 three.two.two 4. four 

Instead, this is what I see (wrong numbering):

1. one 2. two   2.1. two.one   2.2. two.two   2.3. two.three 2.4 three <!-- this is where it goes wrong, when going back to the parent -->   2.1 three.one   2.2 three.two     2.2.1 three.two.one     2.2.2 three.two.two 2.3 four 

I have no clue, does anyone see where it goes wrong?

Here is a JSFiddle: http://jsfiddle.net/qGCUk/2/

like image 662
dirk Avatar asked May 01 '12 23:05

dirk


People also ask

How do you nest a list within a list in HTML?

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.

Does HTML5 support nesting of list?

Note: The <ul> attributes are not supported by HTML5. Example: This example shows a nested unordered list. It is used to nest the list items i.e list inside another list.


2 Answers

Uncheck "normalize CSS" - http://jsfiddle.net/qGCUk/3/ The CSS reset used in that defaults all list margins and paddings to 0

UPDATE http://jsfiddle.net/qGCUk/4/ - you have to include your sub-lists in your main <li>

ol {    counter-reset: item  }  li {    display: block  }  li:before {    content: counters(item, ".") " ";    counter-increment: item  }
<ol>    <li>one</li>    <li>two      <ol>        <li>two.one</li>        <li>two.two</li>        <li>two.three</li>      </ol>    </li>    <li>three      <ol>        <li>three.one</li>        <li>three.two          <ol>            <li>three.two.one</li>            <li>three.two.two</li>          </ol>        </li>      </ol>    </li>    <li>four</li>  </ol>
like image 98
Zoltan Toth Avatar answered Sep 22 '22 08:09

Zoltan Toth


Use this style to change only the nested lists:

ol {     counter-reset: item; }  ol > li {     counter-increment: item; }  ol ol > li {     display: block; }  ol ol > li:before {     content: counters(item, ".") ". ";     margin-left: -20px; } 
like image 34
Moshe Simantov Avatar answered Sep 22 '22 08:09

Moshe Simantov