Closed tabatkins closed 5 years ago
The CSS Working Group just discussed Need to allow stacked pseudo-element selectors in the grammar
, and agreed to the following:
RESOLVED: Generic selector grammar allows stacking pseudo elements and classes. Only certain combos will be made valid, by default everything is invalid
Yeah, this is also necessary because of ::part(…)
and ::slotted(…)
, which allow this as well.
Firefox already supports ::slotted(...)::before
and such so parsing them isn't webkit unique.
::slotted is different, as it selects elements. Same for ::part
Yeah, but the way they are currently specified and implemented violates the current <compound‑selector>
grammar.
Yup, this is a long-needed grammar change to reflect reality. The fact that the Scoping spec explicitly allowed ::slotted()::before
even tho it was grammatically invalid per Selectors just shows that we were behind the ball there. ^_^
Currently, the grammar contains: [ <pseudo-element-selector> <pseudo-class-selector>* ]*
, where the wrapping group has *
instead of ?
, which reads to me as:
╭─────────────────────────────────────────────────────────────────────╮ │ ╭─────────────────────────────────╮ │ ╟─┤ │ ╭─────────────────────────────╮ │ ├─╢ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┱─╯ ╰─┲━━━━━━━━━━━━━━━━━━━━━━━━━┱─╯ │ │ ╰─┨ <pseudo-element-selector> ┠─────┨ <pseudo-class-selector> ┠───̶╰̶─̶╮̶─╯ ╭┺━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━┛ │ ╰──────────────────────────────────────────────────────────────────╯
Which would indicate support for multiple pseudo elements.
...indeed it does. Cool.
I still think the syntax could be simplified.
NVM, thinking about it, the current system provides an easy‑ish way to get all the pseudo‑classes associated with a given pseudo‑element.
In Lists, we've resolved that ::before and ::after can be set to "display: list-item", thus generating markers. However, per Selectors grammar, it's not valid to then write a selector like
ol::before::marker
. (You can stack pseudo-classes after your pseudo-element, but not more pseudo-elements.)This seems unfortunate; if a ::before can generate a marker, you should be able to style that marker.
Additionally, I know that WebKit-derived browsers, at least, do allow pseudo-element stacking, to handle styling some of the UA-specific pseudo-elements.
So, we should change Selectors grammar to allow stacking multiple pseudo-elements in a single compound selector. (Individual grammar restrictions will still restrict what sort of stacks are valid;
::before::before
will be an invalid selector, just like::before:invalid
is invalid today even tho::before:hover
is valid.)Since certain pseudo-classes are reasonable to apply to either of the pseudo-elements in the stack, the two need to be arbitrary interleavable. (For example,
::before:hover::marker
.) This gives us a grammar of: