Skip to content

docs(css): clarify regex negative lookahead analogy for :has() regarding last-child - #45087

Closed
prvthmpcypher wants to merge 1 commit into
mdn:mainfrom
prvthmpcypher:fix/css-has-lookahead-analogy
Closed

docs(css): clarify regex negative lookahead analogy for :has() regarding last-child#45087
prvthmpcypher wants to merge 1 commit into
mdn:mainfrom
prvthmpcypher:fix/css-has-lookahead-analogy

Conversation

@prvthmpcypher

Copy link
Copy Markdown

Summary

This PR addresses and resolves #45038 by clarifying the analogy between regular expression negative lookaheads (?!pattern)\ and CSS :has()\ selectors.

Changes Made

  • In \ iles/en-us/web/css/reference/selectors/_colon_has/index.md, updated the Negative lookahead (?!pattern) section to explain that while .abc:has(+ :not(.xyz))\ handles the case where a next sibling is present and is not .xyz, it does not match when .abc\ is the last element (with no following sibling).
  • Added the recommended CSS pattern (.abc:has(+ :not(.xyz)), .abc:last-child) to fully replicate the negative lookahead behavior for all cases.

Fixes #45038

@prvthmpcypher
prvthmpcypher requested a review from a team as a code owner August 11, 2026 12:32
@prvthmpcypher
prvthmpcypher requested review from estelle and removed request for a team August 11, 2026 12:32
@github-actions github-actions Bot added Content:CSS Cascading Style Sheets docs size/s [PR only] 6-50 LoC changed labels Aug 11, 2026
@Josh-Cena

Copy link
Copy Markdown
Member

Duplicate of #45080. Please check open issues before opening your own.

@Josh-Cena Josh-Cena closed this Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:CSS Cascading Style Sheets docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regexp (?!) CSS selector analogy doesn't hold for last child elements

3 participants