Re: <style scoped> and the cascade

On Wed, Mar 7, 2012 at 1:52 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> On 3/7/12 4:18 PM, Tab Atkins Jr. wrote:
>>
>> Hmm, true.  The problem is worsened by the fact that scoped
>> stylesheets provide an "implicit prelude" that restricts their
>> selectors without increasing specificity, so global selectors that are
>> trying to target the same elements will often naturally be longer.
>>
>> I support Boris's change.
>
>
> There's a similar question about the interaction between two scoped
> stylesheets scoped to nested elements, actually.  Consider this testcase:
>
>  <div>
>   <style id="a" scoped></style>
>   <p>
>     <style id="b" scoped></style>
>   </p>
>   <style id="c" scoped></style>
>  </div>
>
> For descendants of the <p>, I would think that the cascade order should be:
>
>  1)  Global stylesheets
>  2)  Styles from "a" and "c" (sorted by specificity, etc)
>  3)  !important styles from "b"
>  4)  !important styles from "a" and "c" (sorted by specificity)
>  5)  !important global styles
>
> Thoughts?

Yes, the cascade order should follow the nesting order, with deeper
scopes winning over higher scopes (and the reverse for !important).

Once you have this principle, it generalizes to the non-scoped case,
where the global scope is shallower than any element scope.

~TJ

Received on Wednesday, 7 March 2012 22:03:00 UTC