w3c / w3c/csswg-drafts

[css-values-5] toggle() should be a pseudo-class akin to :nth-child()

Open
#9,899 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

selectors-4
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

A few days ago I ran into the problem of styling nested elements and was informed via Twitter that there's already a toggle() function in the draft stage.

However upon a closer look I'm not sure having it as a function is nearly as useful as a psuedo-class in the veins of :nth-child(), such as :nth-descendant().

There are several disadvantage with the toggle() function compared to a hypothetical :nth-descendant() pseudo-class:

  1. Must toggle on a per-property basis, so in case of multiple properties you must use multiple toggle() function and manually sync them up, it gets especially convoluted and verbose if you need to repeat the same value multiple times.
  2. Toggling on a per-property basis also mean you can't logically group multiple values belonging to a single "toggle state" together, they must be intermixed with other toggle states making everything difficult to read.
  3. Forced to manually declare the sequence of values, instead of using the already existing logic we have for :nth-child() with its even, odd and An+B syntax.
  4. No way to toggle based on parent element's nesting level, such as blockquote:nth-descendant(even) .titlebar {background:blue}. To do this with toggle() function you'd need to toggle a variable in the parent and then use said variable in the child element, adding undue complexity.

The above is why I believe toggle() should not be a function at all, but a pseudo-class instead.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CSS Values and Units Level 5 draft's toggle() notation section linked in the issue, then compare its model with the existing :nth-child() pseudo-class and An+B syntax. Done would require a resolved CSSWG design for whether and how toggle() becomes a pseudo-class, followed by corresponding specification changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.