-
Notifications
You must be signed in to change notification settings - Fork 672
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
[selectors-4] [css-nesting-1] pseudo elements need to be clarified to correctly handle relative selectors. #7979
Comments
Number 2. The space is implied by the lack of a |
The space is only implied when the selector doesn't start with a combinator : .foo {
.bar {} /* implied space */
> .bar {} /* no implied space */
} So it depends on what also see : #7346 (comment)
|
@sesse I noticed that Chrome currently does (2). <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
::before {
content: "";
position: fixed;
left: 50px;
right: 50px;
width: 100px;
height: 100px;
background-color: red;
}
}
</style>
</head>
<body>
<div></div>
</body>
</html> equivalent : body {
& ::before {
content: "";
position: fixed;
left: 50px;
right: 50px;
width: 100px;
height: 100px;
background-color: red;
}
} |
I didn't do anything specific for it; it's just that ::before isn't parsed as a combinator. So if you look as the selector More specifically: “Relative selectors begin with a combinator, with a selector representing the anchor element implied at the start of the selector. (If no combinator is present, the descendant combinator is implied.)” These are the combinators: https://csswg.sesse.net/selectors-4/#typedef-combinator
So |
Yup, that is all correct.
This is also clear from
This is related to : #7346
If such a combinator is ever introduced we would have a difference between : .foo {
/* a true combinator -> .foo::before */
:> before {}
/* implied combinator -> .foo ::before */
::before {}
} |
@tabatkins @argyleink ping |
I honestly don't know. I don't find any of this behavior intuitive, but I've been told it is if I only knew Sass. :-) I guess my best explanation here is that |
|
Ha, same here :) I think this issue also illustrates how messy implicit things can become. I don't have a preference between 1 or 2. |
It makes sense if you know it's defined in terms of relative selectors, but I really doubt that's a term most authors will know. E.g., if you make a web search for “relative selector css”, the only two hits among the top 10 that understand the term are MDN and the spec itself. Every other video, tutorial page etc. thinks it's something else (e.g. mixing it up with compound selectors). So this isn't a concept that we can hang authors' intuitions on. |
+1. EDIT: I mean, I was confused by |
If the relative selector
And the most common usecase seems to check if the element itself has the pseudo-element (and not some random descendant).
1 and 2 are hypothetical so I'm assuming 3. Thus Should they? I dunno, I don't use Sass either, so allowing relative nested selectors that don't start with an explicit combinator is completely confusing to me. |
Empirically, Sass treats |
That (I think) is the best way to look at it.
|
We now match Chrome's implementation. |
I would prefer that option 2 ( |
Sass's behavior, and Chrome's, is correct. For historical reasons, while the I wish pseudo-elements didn't have this sort of grammar, but we're stuck with it. @Loirooriol The ":has-allowed pseudo-elements" concept we've carved out isn't for changing the meaning of something like |
Closing as Question Answered, as the specs do have a clear answer. |
Thank you for that, it is much clearer now! |
see : https://www.w3.org/TR/selectors-4/#issue-5830d0c1
Pseudo elements are not allowed in
:has
, so this issue didn't need to be resolved before : #7463With nesting you can now write :
Is that (1) :
or (2) :
I would say it is 1.
::before
starts a new compound selector and has its own implicit "into pseudo tree" combinator as illustrated with.foo::before:hover
vs..foo:hover::before
.The text was updated successfully, but these errors were encountered: