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

[whatwg] Selectors within <style scoped>

From: Alex Russell <slightlyoff@google.com>
Date: Thu, 16 Jun 2011 10:52:21 -0700
Message-ID: <BANLkTimDOQb=7BDLD2uW_jXuoBQZwBXEfxzc8hfaZRgn4GtCfA@mail.gmail.com>
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.
>

Requiring this prefix for things that are ostensibly "scoped" seems
confused. As an author, I more often want the inversion, a scoped stylesheet
explicitly beginning the match from what you refer to as the :scope and an
explicit way to target from the document, say :root.


> 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<http://dev.w3.org/2006/webapi/selectors-api2/#the-scope-pseudo-class>
>
> --
> Lachlan Hunt - Opera Software
> http://lachy.id.au/
> http://www.opera.com/
>
Received on Thursday, 16 June 2011 10:52:21 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:06 UTC