W3C home > Mailing lists > Public > public-css-archive@w3.org > April 2020

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

From: Oriol Brufau via GitHub <sysbot+gh@w3.org>
Date: Fri, 10 Apr 2020 17:20:18 +0000
To: public-css-archive@w3.org
Message-ID: <issue_comment.created-612130111-1586539217-sysbot+gh@w3.org>
@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

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:42:04 UTC