"CSS Counters with nested lists"
Bootstrap 3.3.0 Snippet by gaving

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <h2>CSS Counters</h2> <ul> <li>Parent</li> <li>Parent <ul> <li>Child <ul> <li>Grandchild</li> <li>Grandchild</li> <li>Grandchild</li> </ul> </li> <li>Child <ul> <li>Grandchild</li> <li>Grandchild</li> <li>Grandchild</li> </ul> </li> <li>Child <ul> <li>Grandchild</li> <li>Grandchild</li> <li>Grandchild</li> </ul> </li> </ul> </li> <li>Parent <ul> <li>Child</li> <li>Child</li> <li>Child</li> </ul> </li> <li>Parent <ul> <li>Child</li> <li>Child</li> <li>Child</li> </ul> </li> </ul> </div> </div>
ul { list-style: none; counter-reset: index; } ul li { counter-increment: index; } ul li::before { content: counters(index, ".") "- "; }

Related: See More


Questions / Comments:

CSS counters can be used to create indexing / numbering of elements in the page - all that has to be done is to initialise the counter, increment it and then use a :before or :after pseudo-element to display it.

gaving () - 6 years ago - Reply 0