Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-scoping][selectors] :root should resolve to :host in shadow trees #11000

Open
LeaVerou opened this issue Oct 4, 2024 · 2 comments
Open

Comments

@LeaVerou
Copy link
Member

LeaVerou commented Oct 4, 2024

https://drafts.csswg.org/selectors/#the-scope-pseudo

Currently, if used in regular CSS but outside an @scope rule, :scope resolves to :root. However, this is not super useful within shadow CSS. :host would be a lot more natural.

This would be a breaking change, but I’d wager the prevalence of :scope outside @scope in shadow CSS is so low that we can still make it.

This means the same CSS can be used within Shadow DOM to style the component, as well as using @import ... scope(...) to style light DOM elements.

@sorvell
Copy link

sorvell commented Oct 4, 2024

This means the same CSS can be used within Shadow DOM to style the component, as well as using @import ... scope(...) to style light DOM elements.

This is indeed an annoying pain point right now when trying to share styles. While you can write :where(:host, :scope, :root), it's cumbersome and I believe this isn't currently supported in Safari (bug or unspec'd?).

Separately and for the same reason could :root resolve to :host in a shadow tree?

@LeaVerou
Copy link
Member Author

LeaVerou commented Oct 4, 2024

Separately and for the same reason could :root resolve to :host in a shadow tree?

YES!

Actually, that’s all we need. Since :scope resolves to :root outside @scope, if :root resolves to :host, by proxy :scope also resolves to :host. I’ll rename the issue.

@LeaVerou LeaVerou changed the title [css-cascade] Outside @scope, :scope should resolve to :host in shadow trees [css-scoping][selectors] :root should resolve to :host in shadow trees Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants