W3C home > Mailing lists > Public > www-style@w3.org > August 2012

Re: [css-counters] Counters not in scope scope

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Fri, 17 Aug 2012 11:31:04 -0700
Message-ID: <CAAWBYDAG9-GVjxWn-ahT2DCFLZ=9aLpufc75mqU6B6WmNd8UJw@mail.gmail.com>
To: Elliott Sprehn <esprehn@gmail.com>
Cc: www-style list <www-style@w3.org>
On Thu, Aug 16, 2012 at 11:49 AM, Elliott Sprehn <esprehn@gmail.com> wrote:
> I'm trying to fix and clean up the counter implementation in WebKit
> and came across some confusion in the spec:
>
> http://www.w3.org/TR/CSS21/generate.html#scope
> """
> If 'counter-increment' or 'content' on an element or pseudo-element
> refers to a counter that is not in the scope of any 'counter-reset',
> implementations should behave as though a 'counter-reset' had reset
> the counter to 0 on that element or pseudo-element.
> """
>
> To me this reads that every counter-increment or content: counter(x);
> when there's no scope should reset to 0 so given this example
> http://jsfiddle.net/mLUyP/ you should output all (1)'s since there's
> no counter-reset in the document. Instead WebKit and Gecko output
> (1)(2)(3) twice like the first counter-increment implies a
> counter-reset to 0 *and* establishes a new scope.
>
> Opera's behavior here is totally different:
> http://test.csswg.org/suites/css2.1/20110323/html4/counters-scope-implied-002.htm
>
> Is there a reason for the implied scopes? Why not just reset every
> counter to 0 at the document root?

I think David explains it correctly, but Lists 3 specifies all of
this: <http://dev.w3.org/csswg/css3-lists/#counter>. (I need to
rewrite large chunks of this - it was the second spec I wrote, and I
still wasn't writing clearly enough at that point.)

In a nutshell:

* Whenever a counter scope is established for any reason, the scope
covers the element, its descendants, and it's following siblings (and
their descendants) *up to but not including a sibling that establishes
a scope for the same counter*.
* counter-reset always establishes a new scope on the element.
* counter-increment (and the new counter-set) establish a scope on the
element if and only if the element is not already in the scope of a
counter of that name.  If there's a scope established by an ancestor
or a previous sibling (or a previous sibling of an ancestor), they'll
instead just interact with that counter normally.

~TJ
Received on Friday, 17 August 2012 18:31:52 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:58 GMT