Skip to content

[css-cascade-6] Proposal: "until" pseudo selector #8815

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

Closed
yairEO opened this issue May 7, 2023 · 5 comments
Closed

[css-cascade-6] Proposal: "until" pseudo selector #8815

yairEO opened this issue May 7, 2023 · 5 comments
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-cascade-6

Comments

@yairEO
Copy link

yairEO commented May 7, 2023

Following my StackOverflow question


I would like to propose a pseudo-selector for selecting elements until the selector defined in the :until part is encountered.

The main purpose is a repeating selector, for confined "groups" of matched elements, between certain constraints.

Use-cases for an :until pseudo-selector:

For each div with class active select all of its following (next) <a> siblings up until the first encountered div selector (jsbin).

(the number of <a> elements is unknown)

div.active ~ a:until(div) { color: red; }
<a></a>       
<a></a>       
<div class='active'></div>
<a></a> <!-- should match this -->
<a></a> <!-- should match this -->
<div></div>
<a></a>
<a></a>
<div class='active'></div>
<a></a> <!-- should match this -->

Currently, there is a specificity problem if one simply write the below CSS selectors:

The selectors only match the first "group" of ` elements and then the second selector overrides the first selector for the rest of the anchor elements:

div.active ~ a { color: red; }
div:not(.active) ~ a { color: initial; }

image

@DarkWiiPlayer
Copy link

DarkWiiPlayer commented May 8, 2023

There is already a proposal that would let you do this: #7233

div.active ~~ a { color: red; }
div:not(.active) ~~ a { color: initial; }

@Loirooriol
Copy link
Contributor

Or possibly something like this (if I'm reading #7751 correctly):

@scope-siblings (div.active) to (div) {
  a { color: red; }
}

@mirisuzanne Is that right? I haven't been following this in detail.

@Loirooriol
Copy link
Contributor

Going back to the specific proposal, I don't like that :until does not impose a constraint on the matching element, but on the preceding combinator. This seems more logical:

div.active ~(:not(div)) a { color: red }

So ~ is like +, + * +, + * + * +, etc. but we would restrict it to +, + :not(div) + , + :not(div) + :not(div) +, etc.

But not sure if something like this is worth it if @scope can already cover the usecases.

@mirisuzanne
Copy link
Contributor

The sibling scope at-rule will work for this use-case, @bramus is working on spec text for that.

The issue with doing it as a pseudo-class (which we considered) is related to @Loirooriol's comment: the 'scope-end' element has to be defined in relation to a specific 'scope-start' element, and the selector subject has to be defined in relation to that resulting scope. That means we need to match three distinct selectors to three distinct subjects. There might be ways to do that in a pseudo-class or other selector syntax, but so far it seems clearer in an at-rule, where each of the three selectors has it's own space.

@mirisuzanne mirisuzanne changed the title Proposal: "until" pseudo selector [css-cascade-6] Proposal: "until" pseudo selector May 8, 2023
@tabatkins
Copy link
Member

Yup, this is an @scope issue, and doing it within the Selector syntax itself is fraught.

@tabatkins tabatkins added the Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. label May 8, 2023
@github-project-automation github-project-automation bot moved this to Discussions in Cascade 6 (Scope) Aug 26, 2024
@mirisuzanne mirisuzanne moved this from Discussions to Done in Cascade 6 (Scope) Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-cascade-6
Projects
Status: Done
Development

No branches or pull requests

5 participants