[whatwg] Selectors within <style scoped>

On Thu, Jun 16, 2011 at 2:11 AM, Lachlan Hunt <lachlan.hunt at lachy.id.au> wrote:
> On 2011-06-15 08:40, Roland Steiner wrote:
>>
>> According to the HMTL5 spec, selectors are not limited to children of the
>> scoping element (the parent element of<style scoped>). For example:
>>
>> <div class="foo">
>> ? ? <div>
>> ? ? ? ? <style scoped>
>> ? ? ? ? ? ? .foo p { display: none }
>> ? ? ? ? </style>
>> ? ? ? ? <p>To be or not to be, that is the question.</p>
>> ? ? </div>
>> <div>
>>
>> In above snippet, the selector in the scoped stylesheet would match,
>> causing
>> the<p> ?element to be hidden...
>>
>> The disadvantages:
>>
>> 1.) a scoped style may unexpectedly apply, because an arbitrary ancestor
>> of
>> the scoping element happens to partially match the scoped selector
>
> This is the purpose of the :scope pseudo-class that is defined to match the
> contextual reference elemnt, which for scoped stylesheets, will be the
> parent of the style element.
>
> So you could rewrite the style above to be:
>
> :scope .foo p { display: none }
>
> Then .foo will only match elements within the div.
>
> http://dev.w3.org/2006/webapi/selectors-api2/#the-scope-pseudo-class

This seems like it would allow us to pursue both use cases.

But looking at this with my Web developer hat on, I would almost
_always_ prefix scoped rules with :scope, just to be safe. I certainly
don't want my ".closed .foo { display:none }" to start reacting to
some doofus syndicating my code in the wrong way. I can see how this
logic quickly downgrades ":scope" to syntactic shellack.

I think we should ask how Web developers would view this. I am pretty
sure that their intuitive understanding of <style scoped> is that all
rules are implicitly prefixed with ":scope".

:DG<

>
> --
> Lachlan Hunt - Opera Software
> http://lachy.id.au/
> http://www.opera.com/
>

Received on Thursday, 16 June 2011 10:28:00 UTC