dive into mark

You are here: dive into markArchivesJanuary 2003Auto-numbered nested lists

Monday, January 27, 2003

Auto-numbered nested lists

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>nested lists</title>
<style type="text/css">
ol { counter-reset: item }
li { display: block }
li:before { content: counters(item, ".") ". "; counter-increment: item }
</style>
</head>
<body>
<ol>
  <li>This is a list item</li>
  <li>This is a list item
    <ol>
      <li>This is a nested list item.</li>
      <li>This is a nested list item.</li>
      <li>This is a nested list item.</li>
      <li>This is a nested list item.</li>
    </ol>
  </li>
  <li>This is a list item</li>
  <li>This is a list item</li>
  <li>This is a list item</li>
</ol>
</body>
</html>

This example uses a little-known CSS technique called automatic counters. It is supposed to display the outer list as “1.”, “2.”, “3.”, “4.”, “5.”, and the inner list as “2.1.”, “2.2.”, “2.3.”, “2.4.”. In other words, auto-numbering the inner list with both a major and minor item number.

The reason it is little-known is that it only works in Opera. Internet Explorer numbers them like any other nested list, as if there was no CSS at all. Mozilla doesn’t number either the inner or outer list at all (because it respects the display: block rule that wipes out the normal numbering, but doesn’t understand the counter rules that set up the nested numbering.) Opera has gotten it right for years, since version 5.

I don’t have a point, really. I just thought it was interesting.

Filed under

Respond privately

I am no longer accepting public comments on this post, but you can use this form to contact me privately. (Your message will not be published.)



Recent Stuff For You, Special Price Stay Here
  • Greasemonkey Hacks
Good Stuff Buy The Cow Go Away
Dive Into Python
Powered by Google Drink The Milk Don't Steal

 

posts / comments
© 2001-8 Mark Pilgrim