-
Notifications
You must be signed in to change notification settings - Fork 715
[css-nesting]The parent selector should not be placed inside the subselector #2909
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
Yes? That is indeed what you must do. What do you think it should look like instead? |
@nest .parent {
.foo {
color: red;
}
.foo2 {
color: yellow;
}
.foo3 {
color: blue;
}
} like less, I just write .parent once @tabatkins |
I'm not sure I understand. That seems like ordinary nesting, which you can do with just:
The only reason you'd need to use
If that's the style you want, to keep all of the But your proposal doesn't seem to do anything about that, so I'm not sure I understand what you're trying to propose. |
With your proposal, can someone write: .foo {
@nest .parent & {
& .foo1 { color: red; }
& .foo2 { color: yellow; }
& .foo3 { color: blue; }
}
} Just curious. (Maybe that addresses the OP's question?) |
Yeah, sure. |
(Not sure if i post it in the good place. And sorry for my poor english) It maybe less powerfull than your proposal.
equal this
ExampleThis :
equivalent to :
Think about playing with
|
You can already write this in my proposal as: body aside.left, body aside.right {
& {
color: red;
}
& span.my-sub-span {
color: red;
}
} Your second example can also be written in my proposal just fine. (I'm not going to show it rewritten, because it's long and doesn't demonstrate anything new, just more nesting.) The only exception is that |
Ok... |
I understand.
As an extension of your proposal, i propose an equivalent:
(note the '&' after html.no-js)
Considere a second file "specific-website.css"
And in another project, form.css can be directly included in a link html tag since it can, but does not have '&' inner, it does'nt need a "nested context" to be used. We can have "start with" @nest("^= "), "ends with" @nest("=^ "), @nest("^="), or @nest("=^"). |
Unfortunately this isn't possible, for reasons explained in the Nesting proposal; selectors and declarations have overlapping grammars and can't be told apart with any finite number of tokens; you have to look forward an unbounded amount before you can be sure in all cases whether you're looking at a selector or a declaration. In particular, seeing something like Requiring the Additionally, the
Currently, @import can't even be placed between rules, let alone within them; all So, it's unlikely that |
Okay!... I think the root problem is older. Honestly i doesn't agree with the confusion between style blocks space and selector definition space introduced by actual preprocessors. I think that increase sementic and structure dependencies between css and html. Then i think preprocessors functions are not bad, but in this context appears like the antidote of its own poison... But it's another discussion. And if people wants it, i will need to deal with :) Never mind. I will keep my started idea as a separate preprocessor css-compatible
If it happens one day, it should be better to call it "@include" to avoid possible confusion and respect retro-compatibility... Then i will add "@include" in my preprocessor. Thanks for this note! |
Closing, since the requests in the thread are already possible, and the one wrinkle about the limitations of nesting syntax are now moot since we changed how we parse nested rules. |
About The Nesting At-Rule: @nest
if .parent have three child selectors ".foo",".foo2",".foo3",I must write "@nest .parent &" in every child selectors,this is very tedious
The text was updated successfully, but these errors were encountered: