W3C home > Mailing lists > Public > www-style@w3.org > November 2006

Re: [CSS21] Possible counters() limitation?

From: Paul Sawyer <pauldsawyer@yahoo.com>
Date: Thu, 9 Nov 2006 18:46:13 -0500
Message-ID: <001301c70459$3ee05c40$9459a845@paulsdesktop>
To: <www-style@w3.org>

Since no one has responded to my post on this topic on November 7, 2006 I 
thought I should explain my suggestion a little more thoroughly. The problem 
as Anne van Kesteren originally pointed out is that the CSS2.1 counter model 
does not provide a way to produce hierarchically numbered sections with 
headers. Anne's example was:



                 With a structure such as:



                    <section>

                             <h>LEVEL 1</h>

                             <section>

                                      <h>LEVEL 2</h>

                             </section>

                             <section>

                                      <h>LEVEL 2</h>

                             </section>

                    </section>



                 ... I can't really find the a way to get an outline such 
as:



                    1  LEVEL 1

                    1.1 LEVEL 2

                    1.2 LEVEL 2



To state the problem more generally, CSS2.1 does not provide a way to 
hierarchically number elements that directly nest within themselves. This 
type of numbering is very widely used, in technical books and documents. As 
L. David Baron pointed out, there is no way to tweak the existing CSS 
counter model with out breaking other important counter behaviors.



I believe that there needs to be a way to hierarchically number elements 
that directly nest within themselves. In the example above, I believe that 
the "section" element should be able to hierarchically number itself 
(without any help from the "h" element).



My solution does not change the existing counter behavior at all and it does 
not invent a whole new counter model it just adds the missing functionality 
to the current model. My solution is also very ease to implement in a UA.



Currently when a UA traverses the document tree to generate the counter 
values for each node and it encounters a counter-reset, it must determine if 
the referencing element is a following sibling or a nested element. If it is 
a following sibling, it simply resets the current instance of the counter. 
However, if the referencing element is at a lower nesting level (lower than 
the level that the current instance of the counter was created at), the UA 
must create new instance of the counter and reset that.



My solution is to add a new property, which might be called 
"counter-nested-reset". counter-nested-reset would work similarly to 
counter-reset except that when the UA detects a counter-nested-reset on a 
following sibling, it does not perform the reset. counter-nested-reset only 
performs a reset when it occurs on a element that is at a lower level of 
nesting. Therefore, counter-nested-reset never actually resets an existing 
instance of a counter. It only resets when it creates a new instance of the 
counter.



As I said, UAs already need to distinguish between following siblings and 
nested elements when processing counter-resets. Therefore, adding the code 
to process counter-nested-resets is extremely simple. The code is basically 
a copy of the code that processes counter-reset except that when a following 
sibling is detected it does nothing.


The following style sheet would then produce the desired behavior with the 
above example:

section {counter-nested-reset: item; counter-increment: item}
h:before {content: counters(item, ".") " "}



Note that with this system, an element that directly self-nests can keep 
track of its hierarchical numbering. Therefore, this system would allow 
hierarchically numbered list items to be directly nested within themselves 
which would also be a nice feature.



Paul Sawyer
Received on Thursday, 9 November 2006 23:46:25 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:47 GMT