WordPress Mike
WordPress Mike

Reputation: 458

CSS Counter Only for Child List Items

Is it possible to display only decimal numbers and not the whole numbers at the top level of an ordered list outline? For example:

<ol>
<li>Item 
    <ol>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
    </ol>
</li>
<li>Item
    <ol>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
    </ol>
</li>
<li>Item</li>
<li>Item</li>

CSS

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

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

That would display a list like:

  1. Item
       1.1 Item
       1.2 Item
       1.3 Item

What I would like to achieve is:

Item
   1.1 Item
   1.2 Item
   1.3 Item

Here is a fiddle I've been trying things out with:
http://jsfiddle.net/Py7k8/

Upvotes: 1

Views: 169

Answers (1)

kei
kei

Reputation: 20471

ol {
  counter-reset: section;                
  list-style-type: none;
}
li:before {
  counter-increment: section;                                                
  content: "";
}
li ol li:before {                                             
  content: counters(section,".") " ";
}

DEMO

Upvotes: 4

Related Questions