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

Re: [CSS21] Possible counters() limitation?

From: Bert Bos <bert@w3.org>
Date: Sat, 9 Sep 2006 22:34:50 +0200
To: www-style@w3.org
Message-ID: <20060909203449.GA8070@mygale.sophia.w3.org>

On Sat, Sep 09, 2006 at 02:53:02PM +0200, Anne van Kesteren wrote:

> It seems that the counters() construct doesn't really address the use case  
> of sections and headers. 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

The solution with counter() is simple, though:

    body {counter-reset: h1}

    section {counter-increment: h1; counter-reset: h2}
    section h:before {content: counter(h1) ".\2007  "}

    section section {counter-increment: h2}
    section section h:before {content: counter(h1) "." counter(h2) " "}

Unless there is a requirement that you didn't mention...



Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos                               W3C/ERCIM
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France
Received on Saturday, 9 September 2006 20:34:56 GMT

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