w3c / w3c/csswg-drafts

[css-selectors] Nearest descendant selector

Open
#4,940 13 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

selectors-5
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

Hello, I would like to have a selector for the closest child only, which isn't a direct descendant of the container. It is useful for a carousel with a child (e.g. holding controls) and nested carousels, which shouldn't inherit the styles of the topmost one, while allowing for extra wrappers or supporting cases where we don't fully control the HTML structure.

.wrapper ^ .child to select only the first .child:

<div class="wrapper">
    <div>
        <div class="child"> </div>
    </div>
    <div>
        <div>
            <div class="child"> </div>
        </div>
    </div>
</div>

This has been requested by others before on SO. Thanks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file, test, or entry point is named. Start by reading the selector examples and the 13-comment thread, then review the relevant CSS Selectors specification context. Done means an agreed selector syntax with defined behavior for the nested examples shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.