8

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.

Rocky
  • 5,486
  • 8
  • 32
  • 36

3 Answers3

14

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 */
Krencl
  • 141
  • 1
  • 2
  • I did a slight modification of your code fit it to my taste. It is located in another similar question: http://stackoverflow.com/questions/4098195/can-ordered-list-produce-result-that-looks-like-1-1-1-2-1-3-instead-of-just-1/25298818#25298818 – chelder Aug 14 '14 at 01:51
8

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.

Ariel
  • 25,995
  • 5
  • 59
  • 69
0
body
{
    counter-reset:section;
}

h1
{
    counter-reset:subsection;
}

h1:before
{
    counter-increment:section;
    content:"Section " counter(section) ". ";
}

h2:before 
{
    counter-increment:subsection;
    content:counter(section) "." counter(subsection) " ";
}
body
{
    counter-reset:section;
}

This is the sample of counter-increment and counter-reset.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Rocky
  • 5,486
  • 8
  • 32
  • 36