Re: [csswg-drafts] [css-selectors] Nearest descendant selector (#4940)

@radogado I think what you want is

```css
.wrapper > .child,
.wrapper:not(:has(> .child)) > * > .child,
.wrapper:not(:has(> .child, > * > .child)) > * > * > .child,
.wrapper:not(:has(> .child, > * > .child, > * > * > .child)) > * > * > * > .child,
/* ... */
```

i.e. select a 1st level `.child`, or a 2nd level one if there is no 1st level one, or a 3rd level one if there is no 1st or 2nd level one, and so on.

You need `:has()` for that, because in order to know if a `.child` descendant matches, you need to look at all other descendants of `.wrapper` with a smaller nesting level. But `:has()` is expensive, so it has only been implemented in print engines.

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

Received on Friday, 10 April 2020 17:20:21 UTC