Reputation: 5271
It is easy to get the correct count if ol inside ol the format looks like below
<ol>
<li>item</li>
<li>item
<ol>
<li>item</li>
<li>item</li>
<li>item
</ol>
</li>
<li>item</li>
<li>item</li>
<li>item
<ol>
<li>item</li>
<li>item</li>
<li>item
</ol>
</li>
<li>item</li>
</ol>
However, if I want to put ul inside ol I can't get counter works correctly
<ol>
<li>item</li>
<li>item
<ul>
<li>item</li>
<li>item</li>
<li>item
</ul>
</li>
<li>item</li>
<li>item</li>
<li>item
<ul>
<li>item</li>
<li>item</li>
<li>item
</ul>
</li>
<li>item</li>
</ol>
Is there a way to avoid counting ul ?
Upvotes: 1
Views: 2705
Reputation: 1793
There's a very simple way to fix it. Just use a CSS child selector (>
) so the count only includes <li>
s that are children of the <ol>
.
ol > li::before {
counter-increment: my;
content: counter(my) ;
margin-right: 10px;
}
http://jsfiddle.net/jaxymnh8/1/
Upvotes: 8
Reputation: 1625
You need to add a counter to the sub li
so this is how you would do it
ol,ul {
list-style:none;
}
.count{
counter-reset: section;
}
ol>li {
counter-reset: subsection;
}
ol>li:before {
counter-increment: section;
content: counter(section) ". ";
}
ul li:before {
counter-increment: subsection;
content: counter(section) "." counter(subsection) " ";
}
Upvotes: 2