Can you help me figure out why the numbering of sections is incorrect in this CSS code snippet (http://jsfiddle.net/75MHS/)? When I nest h3
and h4
inside div
elements, the chapter numbers and section numbers are always off by one. However, if I remove the div
containers, the numbering is correct.
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
h3 {
counter-increment: chapter;
counter-reset: section;
}
h3:before {
content: "Chapter " counter(chapter) " ";
}
h4 {
counter-increment: section;
}
h4:before {
content: counter(section) " ";
}
</style>
</head>
<body>
<!-- wrong counter -->
<div><h3>dddd</h3></div>
<div><h4>dddd</h4></div>
<div><h4>dddd</h4></div>
<div><h3>dddd</h3></div>
<div><h4>dddd</h4></div>
<div><h4>dddd</h4></div>
<!-- correct counter -->
<!--
<h3>dddd</h3>
<h4>dddd</h4>
<h4>dddd</h4>
<h3>dddd</h3>
<h4>dddd</h4>
<h4>dddd</h4>
-->
</body>
</html>