The following CSS counter example does not work as expected. The counter for sub-headings should reset after every main heading:
body {
font: smaller sans-serif;
counter-reset: h1 h2;
}
h1:before {
counter-reset: h2;
content: counter(h1) ". ";
counter-increment: h1;
}
h2:before {
content: counter(h1) "." counter(h2) ". ";
counter-increment: h2;
}
<h1>Heading</h1>
<h2>Sub-heading</h2>
<h2>Sub-heading</h2>
<h1>Heading</h1>
<h2>Sub-heading</h2>
<h2>Sub-heading</h2>
However, the following works as expected:
body {
font: smaller sans-serif;
counter-reset: h1 h2;
}
h1:before {
content: counter(h1) ". ";
counter-increment: h1;
}
h1 {
counter-reset: h2;
}
h2:before {
content: counter(h1) "." counter(h2) ". ";
counter-increment: h2;
}
<h1>Heading</h1>
<h2>Sub-heading</h2>
<h2>Sub-heading</h2>
<h1>Heading</h1>
<h2>Sub-heading</h2>
<h2>Sub-heading</h2>
My question is, why does counter-reset
not work inside pseudo elements?