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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<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>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
ul {
list-style: none;
counter-reset: index;
}
ul li {
counter-increment: index;
}
ul li::before {
content: counters(index, ".") "- ";
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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 () - 7 years ago - Reply 0