W3C home > Mailing lists > Public > www-style@w3.org > July 2008

Re: Scoped style sheets.

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 14 Jul 2008 18:00:29 -0500
Message-ID: <dd0fbad0807141600s70958c8cv9e92f94f5530fb02@mail.gmail.com>
To: "Andrew Fedoniouk" <news@terrainformatica.com>
Cc: "Lachlan Hunt" <lachlan.hunt@lachy.id.au>, www-style <www-style@w3.org>, "Ian Hickson" <ian@hixie.ch>

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

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

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

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:27:38 UTC