I'm Dudley Storey, the author of Pro CSS3 Animation. This is my blog, where I talk about web design and development with HTML, CSS and SVG. To receive more information, including news, updates, and tips, you should follow me on Twitter or add me on Google+.

my books

Pro CSS3 Animation book coverPro CSS3 Animation, Apress, 2013

my other blogs

Massive Head CanonMassive Head Canon: Intelligent discussion of movies, books, games, and technology.

my projects

The New DefaultsThe New Defaults — A Sass color keyword system for designers.

CSSslidyCSSslidy — an auto-generated #RWD image slider. 3.8K of JS, no JQuery.

Point-Numbered Lists With CSS Counters

Building legal documents and complex nested lists on web pages

The biggest challenge in ordered lists is creating point-numbered presentations, as you might see in an extensive contract or other legal document, using numbers like 5.1 and 3.7. To gain these while retaining an ordered list structure, we must turn to CSS counters.

Let’s say you want to want to have a series of ordered lists starting with 1.1. First, we must create the correct HTML markup. (I’m using HTML5 shortcuts to save on space).

<h2>Legalese</h2>
<ol>
<li>Flibbert
<ol>
 <li>Flibberme
 <li>Giblet
</ol>
<li>Me Giblets
 <ol>
 <li>Beep
 <li>Bop
 <li>Boop
 </ol>
</ol>

The easiest way to understand CSS counters system is that they act like an odometer that is incremented by encountering specified elements.

First, we set up the ordered list to not show list item numbers:

ol { list-style-type: none; }

Then set up the first counter “odometer” to restart whenever an <ol> element is encountered:

ol { counter-reset: section; }

The odometer will increment with every list item:

li { counter-increment: section; }

And before every (undecorated) list item, create some generated content that includes the current section count:

li:before { content: counters(section, ".") " "; }

The result:

Legalese

  1. Flibbert
  2. Me Giblets

This site helps millions of visitors while remaining ad-free. For less than the price of a cup of coffee, you can help pay for bandwidth and server costs while encouraging further articles.