Re: [csswg-drafts] When using @import scope(), are the imported styles 'nested'? (#11756)

I see, thanks for the explanation. I still maintain that to the extent possible, rules should behave identically to being nested in an `@scope` block. That seems to be a clearer mental model, and it doesn't seem there is a strong justification for the alternate behavior to warrant a departure from it.

Even consistency aside, that seems like the clearer mental model. If authors desire the other behavior where the rest of the selector is essentially a filter, they can make their intent clear by rewriting `section h2` as `h2:is(section *)`.

> I think it could be an acceptable tradeoff for bundlers to require authors to always add an explicit `&` or `:scope`. That doesn't actually limit any capability, it only requires authors to do a bit more typing, right?

Like @mirisuzanne, I also don't understand what purpose this serves. Additionally, I see being able to repurpose existing stylesheets as an important use case for this feature, so anything that requires writing them differently eliminates this.

> Currently, selectors at the top level of a CSS document are not 'relative' to anything. They can't, for example, start with a combinator. Nested selectors are relative to the parent selector. Relative selectors often start with a combinator:
> 
> > h2 { /* not a valid selector */ }
> 
> main {
>   > h2 { /* nesting makes it valid, with implied `&`  */ }
> }
> The first selector here is currently invalid if we apply the stylesheet directly. Would it suddenly become valid when the stylesheet is imported with nesting applied?

This seems orthogonal and likely warrants a new issue: _why_ aren't they valid? We resolved a while ago that outside of nesting, `:scope` and `&` resolve to `:root`. If `> h2` is essentially equivalent to `& > h2`, why wouldn't that be valid in the root scope?

Another orthogonal issue is that many stylesheets define CSS variables under `:root`, which would not match anything for either condition. Perhaps the answer to this is just "they should transition to using `:scope` instead, but I wonder if it may make sense to make `:root` resolve to `:scope` when used inside an `@scope` rule.

-- 
GitHub Notification of comment by LeaVerou
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11756#issuecomment-2689332711 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 27 February 2025 23:23:03 UTC