Re: Scoped style sheets.

On Mon, Jul 14, 2008 at 5:50 PM, Andrew Fedoniouk
<news@terrainformatica.com> wrote:
>
> One more thing about <style scoped />.
>
> What would be a specificity of CSS rules in scoped style sheet?
> Question is in markup:
>
> <html>
> <style>
>  body #content p { color:red; }
> <body>
>  <div #content>
>    <style scoped>
>        p { color:green; }
>    </style>
>    <p>what would be the color of this text?</p>
>  </div>
> </body>
> </html>
>
> It appears as <style scoped> should always be more specific than rules in
> just a <style>.
> Yes/no?

Hmm.  It's certainly tempting to say, "exactly as normal", but that
can cause a lot of problems.  Part of the point of scoping is to state
that you have special styles specifically for the scoped fragment, and
having to deal with specificity issues all the time would be very
annoying.  It's likely to be a very common problem, as well, since the
use of scoping means that you don't need the elaborate targetting
preamble that is sometimes required in global styles (and thus your
scoped styles will naively have a much lower specificity).

So, yeah, you'd want scoped rules to win over unscoped rules
regardless of specificity.  However, you have to address the
interaction with !important.  I believe it's most reasonable to still
have !important rules ignore specificity and apply regardless, meaning
that a global !important rule would override a scoped rule without
!important.

Of course, a scoped !important rule would likely override a global
!important rule, no?

~TJ

Received on Monday, 14 July 2008 23:01:10 UTC