Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create multi-level ordered list in HTML? [duplicate]

Tags:

html

I want this:

1. Main
  1.1 sub1
  1.2 sub2
2. Main2
  2.1 sub3

is it possible to do this in HTML? Thanks.

like image 707
Rocky Avatar asked Oct 17 '11 08:10

Rocky


2 Answers

This solution works for me:

/* hide original list counter */
ol li {display:block;} 
/* OR */
ol {list-style:none;}  

ol > li:first-child {counter-reset: item;} /* reset counter */
ol > li {counter-increment: item;} /* increment counter */
ol > li:before {content:counters(item, ".") ". "; font-weight:bold;} /* print counter */
like image 159
Krencl Avatar answered Nov 07 '22 05:11

Krencl


Yes, at least in a modern browser:

li li:before {
  counter-increment: item;
  content: counter(item) ". ";
}

(The li li is so it only does this after the first level.)

You'll probably need counter-reset as well.

like image 20
Ariel Avatar answered Nov 07 '22 05:11

Ariel