-
Notifications
You must be signed in to change notification settings - Fork 674
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-nesting-1] Clarify when nested rules are equivalents to :is()
#10523
Comments
The article { & { color: red; } }
:is(article) { color: red; }
article { color: red; } In Sass, the The spec examples are not showing literal transformations that happen to your selector, they are showing alternative selectors that have equivalent results.
Does that make sense? |
@mirisuzanne Yes that does make sense and it is incredibly helpful. I want to make sure that I understand this behavior properly:
I know that the nesting behavior superficially looks / acts like Sass. But what I'm really trying to understand is all the ways it isn't like Sass. Sass of course errors on a single nested Do you think it might be beneficial to explain explicitly in the documentation how nesting invokes |
No problem, glad that helped. In the meantime, I'm going to close this as 'question answered' if you don't mind.
right
no, only the
No, see the Editor's Draft (emphasis added):
This is also often equivalent to
As far as I can tell, only the
The replacement is a metaphor, but a fairly reliable one. The The big difference here is that Sass does literal string replacement, which can change the selector meaning based on context – But yes, in your case, the chained-
Besides the impact on specificity, and the inability to do string-concatenation, this thread covers the biggest difference that I would note. Here's a codepen demo of the difference.
I don't believe those assertions are correct. :) But it's possible @tabatkins will want to clarify some of the examples based on this conversation, I'm not sure. |
@mirisuzanne Thank you again for clarifying. I really appreciate you using the term, "chained I would strongly encourage the specifications to use this terminology to help CSS users understand the mechanics.
The reason I made the conclusion, "oh, the parent should also be wrapped in /* multiple selectors in the list are all
relative to the parent */
.foo, .bar {
color: blue;
+ .baz, &.qux { color: red; }
}
/* equivalent to
.foo, .bar { color: blue; }
:is(.foo, .bar) + .baz,
:is(.foo, .bar).qux { color: red; }
*/ I'll weed out the parts that aren't related, and it looks like this: .foo, .bar {
+ .baz {
color: red;
}
}
/* equivalent to
:is(.foo, .bar) + .baz { color: red; }
*/
I ran some tests on specificity, and it appears that any time the parent selectors are a list, they get wrapped in Chrome's dev tools reports specificity and I experimented with my final ruleset and looked at the specificity. .oof {
+ .baz { /*specificity 0,2,0*/
color: orange
}
}
.oof,
div.oof {
+ .baz { /* specificity 0,2,1 */
color: orange;
}
} Is it more accurate to say, "the If that's the case, do you think it might be easier to simplify that "metaphor" as, "in cases of nesting, always think of the nested parent as wrapped in Your explanations have been great and I've found them very insightful; I really appreciate you correcting my assertions. Do you think that Section 3.2's examples could be rewritten and organized so as to only make one clear assertion at a time? The examples written in the spec are very long and often make several assertions in a single example. Complex (using Sass' own documentation for nesting does a great job of providing increasingly-complex examples. Do you think the CSS spec could possibly consider even using Sass' exact examples? I know that the goal here is to not conflate or confuse CSS Nesting or Sass Nesting because the mechanisms are different. But given that Sass got there first (¿probably?), leaning on how Sass has documented behaviors like I'd love to see section 3.2 arranged so that the first examples had nothing to do with |
Wait. When I say "only the
The It seems like you are reading complexity in the examples that doesn't actually exist? In part because they don't distinguish between e.g. I don't mean that all the examples are simple, but they aren't intending to express anything additional with the presence or absence of the But there's something else going on with your read here. Because the I'm always in favor of specs & examples being more clear where possible. But there are a lot of specs, and it can be a lot of work – especially since different people will understand different phrasings. So it's hard to get perfect, and comes down to time & focus & priorities. The good news is, if you have ideas for improvements, anyone can submit a PR. :) |
Could you provide clarity for when
:is()
is used for selectorsIn the examples section, I spotted some examples that seem to suggest contradictory situations where
:is()
is an equivalent to the nested code.This example suggests that
:is()
is an equivalent when there's a list of multiple selectors:And this seems consistent with this example, where it is not considered to be an equivalent to an
:is()
However, I then see this example where there is not a list of selectors, but it's called an "equivalent" of an
:is()
The difference between the first and third examples is that in the first, the parent is a single selector while in the third there is a general-descendant selector. I wouldn't consider
.ancestor .el
to be a selector list because there's no comma indicating more selectors.Request:
Could you please explicitly describe when nested CSS produces an equivalent to
:is()
. i.e.::is()
:is()
Could you provide clarity on the equivalency of
&
and:is()
In the draft, in the section about mixing nesting rules and declarations, There is this example
I understand the point about order. However, I also observe an implication regarding what
&
does. This suggests that&
will produce an:is()
if it's neither preceded or seceded by another selector.However, this contradicts an earlier example:
Request
Could the incorrect example be removed? Or if they're somehow both correct, could you explain how?
Could you explicitly call out the conditions under which
&&
would work.The specifications give this example
But it has also been made very clear that the
&
is not capable of sass-like concatenation.So then what is the output of these examples?
The examples, as they're given, suggest one of these produces an error:
unless the
&
is actually always an equivalent to:is()
. In which case each condition produces valid selectors:But if this is the case, that contradicts this example where the
&
seems to be "consumed".Request
Could you expand the "Nesting Selector" section and explain when
&
is an equivalent to:is()
. Could you add a section that explicitly calls out how behavior may differ with a type selector? Maybe add an example of&&
to the slightly rephrased example with type selectorsThe text was updated successfully, but these errors were encountered: