-
Notifications
You must be signed in to change notification settings - Fork 711
[css-nesting] A proposal, using a pseudo-class #5491
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
Could |
It's more verbose, but technically anything could be used. The proposal is really for the use of a pseudo-selector (and some tweaks around specificity). Naming is secondary. That said, "scope" is really the wrong concept, I think. There's not really scope within the CSS document. A nested-selector-reference really isn't related to the cascade or document tree; it's only related to the stylesheet, so scope doesn't exist. |
Regarding Sebastian |
I suspected something like this, but I wasn't sure if this was clear in the spec. So, to be clear, I wouldn't be suggesting outside of spec conformance. Something like |
Closing, since the WG explicitly accepted the current syntax (using |
A proposal
Related to the CSS Nesting proposal...
I was re-reading this issue, in which I talked about the conflict between the CSS Nesting proposal and Sass / Less (/ PostCSS, etc)
I think the CSS nesting proposal can be satisfied without conflicting with Sass / Less, and more closely align with CSS, by the use of pseudo-class. Specifically, replacing
&
with:and()
(as an analog to:not()
)It would be:
This would be the equivalent of:
That is, like
:where()
,:and()
would add 0 specificity. (Note: this is different from the current CSS Nesting proposal, which likens the "and selector" to:is()
, not:where()
, but the proposal also has unique specificity rules.)With
@nest
Similarly, I think the proposal is right that the use of
@nest
is necessary to remove ambiguity when the "and selector" is used within a nested selector (vs the start of the nested rule), as in:This would be the equivalent of:
Using at root
If
:and()
is not nested, it would just collapse, as in, these two are equivalent, both in what they select, and in specificity:Uses with Less / Sass / PostCSS
This proposal would allow co-mingling with languages that currently support
&
, as in, with this input:The Less output would (could) be:
In other words, it's no longer ambiguous whether or not rules should flatten, and there's no conflict between the meaning of
&
in the existing CSS Nesting proposal and its (different) meaning in Sass / Less.Other syntaxes
I used
:and()
vs:and
because it seems more semantically similar to:where()
,:not()
,:is()
etc; that is, that it's returning a selector to match, even if it doesn't have arguments. However, CSS spec authors may feel that:and
is sufficient, as in:My feeling was also that arguments may be added to
:and()
in the future, such as partial matching of selectors, but CSS spec authors may disagree.Another syntax possibility I considered, for brevity, would be something like an empty pseudo-class, as in
:()
.As in:
This has the drawback of no longer being a valid pseudo-class, but may be an improvement over
&
.Changes to CSS parsing
Obviously, like the CSS Nesting proposal with
&
, a change would be needed to allow the "and identifier" at the start of a rule, but unlike the&
proposal, IMO this change is not a significant, since:and()
is a valid selector.Thoughts welcome.
The text was updated successfully, but these errors were encountered: