Adding counter for ordered list and reset start - HTML CSS CSS Widget

HTML CSS examples for CSS Widget:OL

Description

Adding counter for ordered list and reset start

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
ol {<!--   w  w w .ja v  a  2s .com-->
   counter-reset:topLevel;
}

li {
   counter-increment:topLevel;
   margin-left:2em;
}

li:not(.hasChild)::before {
   content:counter(topLevel) '. ';
   margin-right:0.4em;
}

ol ol {
   counter-reset:secondLevel;
}

ol ol li {
   counter-increment:secondLevel;
}

ol ol li::before,
ol li.hasChild ol li::before {
   content:counter(topLevel) counter(secondLevel, lower-alpha) '. ';
}
</style> 
 </head> 
 <body> 
  <ol> 
   <li>Foo</li> 
   <li class="hasChild"> 
    <ol> 
     <li>bar</li> 
     <li>baz</li> 
    </ol> </li> 
   <li>Something else...</li> 
  </ol>  
 </body>
</html>

Related Tutorials