HTML Element Style How to - Create Dynamic Numbered Divs








Question

We would like to know how to create Dynamic Numbered Divs.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body {<!--   w w  w  .ja v  a 2  s  .co m-->
  counter-reset: section;
}

div.top div:before {
  counter-increment: section;
  content: counter(section) ') ';
}
</style>
</head>
<body>
  <div class="top">
    <div>Some content goes here</div>
    <div>More content goes here</div>
    <div>Yep, more content</div>
  </div>
  <div class="top">
    <div>Some content goes here</div>
    <div>More content goes here</div>
    <div>Yep, more content</div>
  </div>
</body>
</html>

The code above is rendered as follows: