Skip to content
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] Specificity of contextually-invalid selectors. #9600

Closed
emilio opened this issue Nov 15, 2023 · 3 comments
Closed

[css-nesting] Specificity of contextually-invalid selectors. #9600

emilio opened this issue Nov 15, 2023 · 3 comments

Comments

@emilio
Copy link
Collaborator

emilio commented Nov 15, 2023

Consider something like:

<!doctype html>
<style>
p {
  color: green;
}

*, ::before {
  & * {
    color: red;
  }
}

:is(*, ::before) * {
  color: purple;
}
</style>
<p>Which color is this?

That's red in browsers, quite surprisingly, because ::before, even though is invalid when nested (:is(*, ::before) or so wouldn't parse it), still contributes to specificity. p should win due to specificity otherwise, and the text should be green.

That seems pretty confusing? It's even more confusing when nesting :has() etc. But "fixing" it is actually relatively annoying.

What is the expected result here? What should be the expected result of something like nesting :has() inside :has() which suffers from the same issue?

cc: @dshin-moz, @andruud, @tabatkins, @LeaVerou, @mdubet

@Loirooriol
Copy link
Contributor

Loirooriol commented Nov 15, 2023

This is also exposing the fact that Firefox and WebKit consider the specificity of a pseudo-element to be the same as a type selector, while Blink seems to treat it as a class selector? I believe this might not be observable before CSS nesting.

<!DOCTYPE html>
<style>
p { border: 20px solid }

*, ::before { & { border-left-color: red; }}
p { border-left-color: green; }

p { border-right-color: red; }
*, ::before { & { border-right-color: green; }}

*, ::before { &.p { border-top-color: red; }}
.p.p { border-top-color: green; }

.p.p { border-bottom-color: green; }
*, ::before { &.p { border-bottom-color: red; }}
</style>
<p class="p">Which color is this border?</p>

https://crbug.com/1474144

@emilio
Copy link
Collaborator Author

emilio commented Nov 15, 2023

I don't know what Blink is doing, but the specificity of pseudo-elements should be the type selector's, unless I'm reading https://drafts.csswg.org/css2/#specificity wrong:

count the number of element names and pseudo-elements in the selector (= d)

moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 15, 2023
For now, do the same as pseudo-elements, which is effectively to keep
them in the replaced selector but don't match them. Avoid crashing in
this case.

I filed w3c/csswg-drafts#9600 since this issue
isn't specific about :has(), and depending on the result of that
discussion, the "proper" solution might be different.

Differential Revision: https://phabricator.services.mozilla.com/D193663

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1864647
gecko-commit: 69bede2c30ec37c0a9b3b44879e28a5dd1c0b1c5
gecko-reviewers: dshin
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Nov 16, 2023
…shin

For now, do the same as pseudo-elements, which is effectively to keep
them in the replaced selector but don't match them. Avoid crashing in
this case.

I filed w3c/csswg-drafts#9600 since this issue
isn't specific about :has(), and depending on the result of that
discussion, the "proper" solution might be different.

Differential Revision: https://phabricator.services.mozilla.com/D193663
moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 16, 2023
For now, do the same as pseudo-elements, which is effectively to keep
them in the replaced selector but don't match them. Avoid crashing in
this case.

I filed w3c/csswg-drafts#9600 since this issue
isn't specific about :has(), and depending on the result of that
discussion, the "proper" solution might be different.

Differential Revision: https://phabricator.services.mozilla.com/D193663

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1864647
gecko-commit: 69bede2c30ec37c0a9b3b44879e28a5dd1c0b1c5
gecko-reviewers: dshin
ErichDonGubler pushed a commit to ErichDonGubler/firefox that referenced this issue Nov 17, 2023
…shin

For now, do the same as pseudo-elements, which is effectively to keep
them in the replaced selector but don't match them. Avoid crashing in
this case.

I filed w3c/csswg-drafts#9600 since this issue
isn't specific about :has(), and depending on the result of that
discussion, the "proper" solution might be different.

Differential Revision: https://phabricator.services.mozilla.com/D193663
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Nov 21, 2023
…shin

For now, do the same as pseudo-elements, which is effectively to keep
them in the replaced selector but don't match them. Avoid crashing in
this case.

I filed w3c/csswg-drafts#9600 since this issue
isn't specific about :has(), and depending on the result of that
discussion, the "proper" solution might be different.

Differential Revision: https://phabricator.services.mozilla.com/D193663

UltraBlame original commit: 69bede2c30ec37c0a9b3b44879e28a5dd1c0b1c5
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Nov 21, 2023
…shin

For now, do the same as pseudo-elements, which is effectively to keep
them in the replaced selector but don't match them. Avoid crashing in
this case.

I filed w3c/csswg-drafts#9600 since this issue
isn't specific about :has(), and depending on the result of that
discussion, the "proper" solution might be different.

Differential Revision: https://phabricator.services.mozilla.com/D193663

UltraBlame original commit: 69bede2c30ec37c0a9b3b44879e28a5dd1c0b1c5
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Nov 21, 2023
…shin

For now, do the same as pseudo-elements, which is effectively to keep
them in the replaced selector but don't match them. Avoid crashing in
this case.

I filed w3c/csswg-drafts#9600 since this issue
isn't specific about :has(), and depending on the result of that
discussion, the "proper" solution might be different.

Differential Revision: https://phabricator.services.mozilla.com/D193663

UltraBlame original commit: 69bede2c30ec37c0a9b3b44879e28a5dd1c0b1c5
@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed [css-nesting] Specificity of contextually-invalid selectors., and agreed to the following:

  • RESOLVED: contextually-invalid selectors have a specificity of zero
The full IRC log of that discussion <Frances> Alan: next is css-nesting
<matthieud> q+
<Frances> Emilio: About what happens when nesting invalid pseudo-element. Keeps sort of being valid, reuse selector from the outside. Behavioral specificity of nesting doesn't seem defined.
<astearns> ack matthieud
<TabAtkins> I have no opinion on this issue, happy to clarify/edit whatever the group wants.
<Frances> matthieu: Weird that specificity is taken in account. Keep invalid selector, we don't take specificity in account.
<Frances> Emilio: seems fine to me, would make behavior of nesting and not nesting as consistent, makes sense. Part of the way to prevent is by sharing memory, need to make specificity not count.
<Frances> Alan: Defining a behavior shouldn't have too much backwards compatibility risk possibly.
<Frances> Emilio: Right now are consistent in reusing the specificity, other cases like :has(:has)
<Frances> Alan: Any other comments or questions?
<Frances> PROPOSAL: Specify contextually-invalid selectors via nesting
<Frances> Emilio: nesting doesn't have specificity at the moment.
<astearns> PROPOSAL: contextually-invalid selectors have a specificity of zero
<Frances> Matthieu: Specific wording?
<Frances> Emilio: Make it behave the same as the regular selector list
<Frances> RESOLVED: contextually-invalid selectors have a specificity of zero

github-actions bot pushed a commit to Loirooriol/stylo that referenced this issue Mar 17, 2024
…shin

For now, do the same as pseudo-elements, which is effectively to keep
them in the replaced selector but don't match them. Avoid crashing in
this case.

I filed w3c/csswg-drafts#9600 since this issue
isn't specific about :has(), and depending on the result of that
discussion, the "proper" solution might be different.

Differential Revision: https://phabricator.services.mozilla.com/D193663
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants