Re: QSA, the problem with ":scope", and naming

On Thu, Oct 20, 2011 at 14:08, Tab Atkins Jr. <jackalmage@gmail.com> wrote:

> <style scoped> should (I think) have three cases:
>
> 1. Selector without :scope - same as .find
> 2. Selector with :scope - Same as #1, but also including the context node.
> 3. Selector in @global - run the selector across the entire document,
> filter the results to only be the context node and its descendants.
>
> (Some people disagree with me on this, and think that #1 and #2 should
> be merged to always include the context node.  That's acceptable, but
> I don't like it as much.)
>

The - very valid IMHO - main argument for <style scoped> to always include
the scoping element was to allow for easy migration. I.e., where currently
you'd use

<style>
    #menu .foo { color: green }
</style>

<div id="menu">
    <div class=foo>
        Will be green
    </div>
</div>
<div class=foo>
    Will NOT be green
</div>

You could just stick the stylesheet under the div and add 'scoped':

<div id="menu">
    <style scoped>
        #menu .foo { color: green }
    </style>
    <div class=foo>
        Will be green
    </div>
</div>
<div class=foo>
    Will NOT be green
</div>

In browsers that don't support 'scoped', this would still work. Where
'scoped' is supported, this doesn't change much per se, except that those
style rules don't need to be checked outside the scope. Once a majority of
browsers support <style scoped> one can then proceed to simplify the rules
and remove '#menu' (admitted caveat: where this then doesn't create an
ambiguity with the scoping <div>).


- Roland

Received on Thursday, 20 October 2011 08:06:58 UTC