Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make css counter works with css selector?

Tags:

html

css

I'was trying to use css counter... This is my css code:

div.primaries div.entries>div.meaning:first-child:before {
    counter-increment: section;
    content: counter(section);
}

and the part of html

<div class="primaries">
<div class="headword entries">
<div class="meaning terms">
<span class="meaning terms text">A collection of items of the ...</span>
</div>
<div class="meaning entries">
<div class="example terms">
<span class="example terms text">an arms <em>cache</em></span>
</div>
</div>
<div class="meaning entries">
<div class="example terms">
<span class="example terms text">a <em>cache</em> of gold coins</span>
</div>
</div>
</div>
<div class="headword entries">
<div class="meaning terms">
<span class="meaning terms text">A hidden or inaccessible ...</span>
</div>
</div>
<div class="headword entries">
<div class="meaning terms">
<span class="meaning terms text">An auxiliary memory from ...</span>
</div>
</div>
</div>

I did not use any "counter-reset". However, every number outputed was 1. So, why it is always 1?

like image 215
elric Avatar asked Aug 18 '11 08:08

elric


1 Answers

Add this and I think it will do as you will:

div.primaries
{
  counter-reset: section;
}

See it work at jsfiddle/Larry/ev758/.

like image 50
Niclas Larsson Avatar answered Oct 06 '22 00:10

Niclas Larsson