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

[whatwg] Selectors within <style scoped>

From: Roland Steiner <rolandsteiner@google.com>
Date: Tue, 20 Sep 2011 16:35:32 +0900
Message-ID: <CACFPSphX8eG1kv8RnQ9WCEmBPAzebOGcDFeTuMPd5Z0d0Jzxpg@mail.gmail.com>
On Thu, Sep 15, 2011 at 9:55 AM, Ian Hickson <ian at hixie.ch> wrote:

> [...]

However, as easy as that appears at first blush, I fear it would be seem
> quite magical to authors who have trouble enough understanding CSS as it
> is. Consider:
>
>   <aside>
>    <section>
>     <style scoped>
>      aside section h1 { ... } /* matches nothing */
>      aside section:scope h1 { ... } /* matches h1 below */
>     </style>
>     <h1>Example</h1>
>     ...
>    </section>
>   </aside>
>
> Never before in CSS has making a selector more specific actually increased
> the number of elements it can match.


That is a very good point!


With :root doing the magic, you're really using :root as an @-rule; you
> might as well at that point actually do so:
>
>     <style scoped>
>      section > h1 { border-bottom: solid; }
>      @global body.homepage h1 { color: red; }
>      @global body.archive h1 { color: gray; }
>     </style>
>
> This does have the advantage of meaning there's no magic. Where do
> implementors stand on this? Are @rules an acceptable solution? (If so,
> we'd want to pass it by the CSSWG first.)
>

On first glance (without having looked at code and potential interactions of
@-rules) "@global" really seems much nicer, esp. for the above given reason.
It's also visually easier to parse, IMHO.

It would also make a nice parallel with the proposed queryScopedSelector
when explaining all of this to authors: @global -> querySelector, no @global
-> queryScopedSelector.


- Roland
Received on Tuesday, 20 September 2011 00:35:32 UTC

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