Re: [csswg-drafts] [css-selectors] Standardise `:⁠(‑moz‑)first‑node` and `:⁠(‑moz‑)last‑node` (#3216)

+1 to the use case. I've needed this several times. Off the top of my head, one of them was for styling an icon component inside buttons, to decide whether this was an icon-only button vs an icon before the button text vs an icon after the button text.

We also take text nodes into account all over the place (e.g. as flex/grid children), so it's weird that we pretend they don't exist in selectors.

As was mentioned in the call, there are two core use cases:
1. Selecting and styling the text node *itself*, presumably via a pseudo-element (we had a draft for `::text` at some point many years ago but I cannot find it)
2. Selecting *elements* based on their relationship to any text nodes (e.g. are they preceded by any text nodes?)

These cannot be addressed by the same solution unless these `::text` pseudo elements can be selected separately and can be used as combinator operands (which is fine, just unprecedented).

I think it's ok to use "node" to mean "non-blank text node". We're already using "child" differently than how it's used in the DOM 😀 

Another issue that wasn't mentioned is that even if we guarantee that an element has no (non-blank) text node before it, that doesn't guarantee it's actually the first or last child layout-wise, since there's always `::before`/`::after` 😀 


-- 
GitHub Notification of comment by LeaVerou
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/3216#issuecomment-4298351943 using your GitHub account


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

Received on Wednesday, 22 April 2026 17:08:05 UTC