Re: [CSS2.1] Counters

On Thursday 2005-06-16 09:38 +0200, Staffan Måhlén wrote:
> On 15 Jun 2005 at 9:42, L. David Baron wrote:
> > > to something like:
> > > "
> > > The scope of all counters used in a document are reset to 0 at the 
> > > root element unless explicitly set to a different value. Each element
> > > that has 'counter-reset' for a counter creates a new scope that 
> > > includes its descendants.
> > > "
> > 
> > This would not only break Hn numbering, but would also cause lists
> > numbered using counters() to all have an additional "0." at the
> > beginning of the number, e.g. "0.10.3" instead of "10.3".
> > 
> 
> Ok that makes sense i suppose. Just to make sure i get it, you want
> to allow headings to be scope-generating without being nested in the
> document, rather than use the list-method where a common ancestor
> is needed?
> h1 {counter-reset: h2 0 h3 0 h4 0...}
> h2 {counter-reset: h3 0 h4 0...}

Yes.  I've actually used the following to number headings:

  html { counter-reset: h2 h3 h4 h5 h6; }
  h2:not(.no-num)   { counter-reset:    h3 h4 h5 h6; counter-increment: h2; }
  h3:not(.no-num)   { counter-reset:       h4 h5 h6; counter-increment: h3; }
  h4:not(.no-num)   { counter-reset:          h5 h6; counter-increment: h4; }
  h5:not(.no-num)   { counter-reset:             h6; counter-increment: h5; }
  h6:not(.no-num)   {                                counter-increment: h6; }

  h2:not(.no-num):before { content: counter(h2) ". "; }
  h3:not(.no-num):before { content: counter(h2) "." counter(h3) ". "; }
  h4:not(.no-num):before { content: counter(h2) "." counter(h3) "." counter(h4) ". "; }
  h5:not(.no-num):before { content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". "; }
  h6:not(.no-num):before { content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "; }

> The second problem could perhaps be addressed in the
> definition of the counters function, by making it not include the
> "initital" reset.

Although that rule would require an exception for when the root reset is
the only one in scope.  It's simpler to avoid exceptions on exceptions.

-David

-- 
L. David Baron                                <URL: http://dbaron.org/ >
          Technical Lead, Layout & CSS, The Mozilla Foundation

Received on Thursday, 16 June 2005 15:39:22 UTC