W3C home > Mailing lists > Public > whatwg@whatwg.org > July 2011

[whatwg] Selectors within <style scoped>

From: Roland Steiner <rolandsteiner@google.com>
Date: Wed, 20 Jul 2011 12:52:55 +0900
Message-ID: <CACFPSpiHXZ2KsUWo6KiSXCt0RVdhSAEpP_QPcKpNmodCbKn0fQ@mail.gmail.com>
On Wed, Jul 20, 2011 at 12:47 AM, Tab Atkins Jr. <jackalmage at gmail.com>wrote:

> On Tue, Jul 19, 2011 at 6:11 AM, Boris Zbarsky <bzbarsky at mit.edu> wrote:
> > On 7/19/11 12:30 AM, Roland Steiner wrote:
> >>
> >> I think one could argue for either case. Personally, I think it's
> >> advantageous to include the scoping element (i.e., use ":scope foo .bar,
> >> foo:scope .bar"), in order to be able to do style the scoping element
> >> itself rather than its children individually, e.g.
> >>
> >> :scope { background-color: mauve; }
> >
> > Hmm.  I agree this is a useful thing to do, but perhaps it's better
> > accomplished by not prepending ":scope " to selectors which have a :scope
> in
> > the first sequence of simple selectors in addition to ones that have
> :root
> > there?
> >
> > This would still not make "foo .bar" match if the scope is a foo, but
> would
> > we actually want to match?
>
> I think it's best for that case to *not* match.  Otherwise, you have
> to explicitly remember to add a :not(:scope) to every rule that might
> match the scoping element.
>

You could just prefix ":scope " instead, i.e., write ":scope foo" if you're
worried that foo might match the scoping element.


> It's very easy to style the scoping element by using :scope explicitly.


I kinda agree with the assessment, but from a puritanical point of view,
given that :scope is a pseudo-class it feels strange that with <foo> as
scoping element the more specific "foo:scope" would match, but the more
generic "foo" wouldn't (even though it still is the scoping element). Also,
the same "foo" matches again if there is a ":root" further to the left.

But adding :scope into the discussion raises the question whether matching
should continue even in the absence of :root - e.g.,

baz :scope .bar

It would seem natural that with this rule, matching would go past the
scoping element, given that it's explicitly identified. That means, the
matching algorithm would go along the lines of:

.) match up to a child of the scoping element
.) match the scoping element and upwards ONLY IF the current selector
sequence contains :scope or the first selector sequence contains :root

if the scoping element is not per default included, or

.) match up to the scoping element
.) match upwards ONLY IF the scoping element was explicitly matched with
:scope, or if the first selector sequence contains :root

if it is.


- Roland
Received on Tuesday, 19 July 2011 20:52:55 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:34 UTC