[csswg-drafts] [css-values-5] toggle() should be a psuedo-class instead similar to :nth-child() (#9899)

miragecraft has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-values-5] toggle() should be a psuedo-class instead similar to :nth-child() ==
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](https://drafts.csswg.org/css-values-5/#toggle-notation).

However upon a closer look I'm not sure solving the problem of styling nested elements via a function is the ideal solution as I feel a psuedo-class in the veins of `:nth-child()` selector is much more useful, 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()` selector 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.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9899 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 2 February 2024 16:32:23 UTC