Re: <style scoped> and the cascade

On Wed, Mar 7, 2012 at 2:18 PM, Ian Hickson <ian@hixie.ch> wrote:
> On Wed, 7 Mar 2012, Boris Zbarsky wrote:
>> I've been looking into scoped stylesheets, and I'm not sure that the way
>> the spec currently places them in the CSS cascade makes sense.  If the
>> intent is for them to be used for styling a particular subtree, it seems
>> like they should probably come later than global document sheets in the
>> cascade; otherwise you can end up with global sheets accidentally
>> overriding scoped styles, which makes it difficult to really use scoped
>> styles effectively.
>
> I'm happy to change the scoping to work with new cascade levels, but it's
> hard to spec that cleanly without supporting infrastructure on the CSS
> side, so I'd rather only do that if the relevant CSS specs can first be
> changed to support the concept of multiple nested cascade levels.

Everything you need should already be there - just add the concept of
'scope' to the author origin, such that for any two scoped styles A
and B, if B's scoping element is a descendant of A's scoping element,
B's styles have a higher weight than A's styles. (If A and B don't
have an ancestor/descendant relationship, the relative weighting is
undefined, but they can't ever apply to the same elements anyway.
Note: we should make sure this invariant remains true.) Scoped styles
always have a higher weight than global styles.

Alternately, just say that document order is increasing weight order.

Until we produce a CSS method of defining scoping (@scope rule,
anyone?) I think it's appropriate for HTML to define this.

~TJ

Received on Wednesday, 7 March 2012 23:51:28 UTC