22.12.2013 Views

W3C CSS2 Cascading Style Sheets, level 2 - instructional media + ...

W3C CSS2 Cascading Style Sheets, level 2 - instructional media + ...

W3C CSS2 Cascading Style Sheets, level 2 - instructional media + ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

will only reset ’imagenum’. To reset both counters, they have to be specified<br />

together:<br />

H1 { counter-reset: section -1 imagenum 99 }<br />

12.5.1 Nested counters and scope<br />

Counters are "self-nesting", in the sense that re-using a counter in a child<br />

element automatically creates a new instance of the counter. This is important for<br />

situations like lists in HTML, where elements can be nested inside themselves to<br />

arbitrary depth. It would be impossible to define uniquely named counters for<br />

each <strong>level</strong>.<br />

Example(s):<br />

Thus, the following suffices to number nested list items. The result is very<br />

similar to that of setting ’display:list-item’ and ’list-style: inside’ on the LI element:<br />

OL { counter-reset: item }<br />

LI { display: block }<br />

LI:before { content: counter(item) ". "; counter-increment: item }<br />

The self-nesting is based on the principle that every element that has a<br />

’counter-reset’ for a counter X, creates a fresh counter X, the scope of which is<br />

the element, its preceding siblings, and all the descendants of the element and<br />

its preceding siblings.<br />

In the example above, an OL will create a counter, and all children of the OL<br />

will refer to that counter.<br />

If we denote by item[n] the n th instance of the "item" counter, and by "(" and ")"<br />

the beginning and end of a scope, then the following HTML fragment will use the<br />

indicated counters. (We assume the style sheet as given in the example above).<br />

<br />

item <br />

item <br />

<br />

item <br />

item <br />

item <br />

<br />

item <br />

<br />

<br />

<br />

<br />

item <br />

<br />

item <br />

item <br />

<br />

<br />

item <br />

item <br />

<br />

The ’counters()’ function generates a string composed of the values of all<br />

counters with the same name, separated by a given string.<br />

162

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!