-
Notifications
You must be signed in to change notification settings - Fork 716
[css-cascade-6] Named scopes proposal #9742
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
Comments
I think a scope statement would be useful too? It would be similar to a layer statement. Create a named scope using a scope statement: @scope foo (.start) to (.end); Then use it without specifying @scope foo {
p { color: red; }
} |
That would be the @scope duplicate (.outer) {
@scope duplicate (.inner) {
/* Use the inner version of duplicate? */
:scope(duplicate) .test {
background: lightgreen;
}
}
} I'm less sure about a solution for reusable named scopes… @scope foo (.start) to (.end);
@scope foo {
p { color: red; }
}
/* does this change the definition of foo for the above paragraph? */
@scope foo (.end) to (.another); I would expect the later statement to override the former, but that becomes a very surprising behavior if the two definitions of |
@mirisuzanne Ah that totally makes sense, I didn't realize that's what was meant by "naming scopes as a way to reuse their selectors". Should I move it into a separate issue? And maybe this issue should also be renamed to make it more clear. |
Yeah, opening a new issue and clarifying the title here both seem like good ideas. We'll also have to keep in mind that this syntax is the 'obvious' syntax for both features. Which makes it potentially a confusing syntax for either one. |
A few quick assorted thoughts (in a brainstorm mode):
…Ok, maybe I should stop for now :) Many of these could be potentially opened as separate issues, but it will make sense to do only if the proposal itself will be accepted. |
I am noticing that if we treat these as distinct issues, they are very likely to end up in conflict. I think someone should write up a more complete proposal here, thinking about both uses and how they interact. |
This issue is a follow-up to the previous issue: #9741
In that issue, I explored the way
:scope
works in a nested context:My proposal consists of two parts:
@scope
(https://drafts.csswg.org/css-cascade-6/#scope-syntax), allowing specifying the<scope-name>
as a<custom-ident>
(or<dashed-ident>
?), in a way similar (syntax-wise, not behavior-wise though) how we can specify a name for containers (https://drafts.csswg.org/css-contain-3/#container-rule) with a<container-name>
.:scope
pseudo-class, which could be used with the scope name inside, like:scope(my-scope)
(or:scope(--my-scope)
if we'd decide on<dashed-ident>
).This way, we could do something like this:
Basically, allowing specifying any specific scope defined around our selector.
Some things to think about:
&
, where we'd retain the scope root's selector's specificity? I'm not sure of the use-cases for that, probably could be a separate proposal in itself.Use cases:
@at-root
in Sass, or root reference in Stylus. This could work already with the:scope
, but only unless a nested scope is introduced, in which case we will lose the access to the root scope.Out of this proposal's scope (sorry): naming scopes as a way to reuse their selectors: this is probably a job for CSS-extensions (label, spec; I did not find a good single issue to mention).
The text was updated successfully, but these errors were encountered: