content icon indicating copy to clipboard operation
content copied to clipboard

Next/Subsequent Sibling Selectors should have examples of how to select Previous/Preceeding elements

Open ChrisFloofyKitsune opened this issue 2 years ago • 1 comments

MDN URL

https://developer.mozilla.org/en-US/docs/Web/CSS/Next-sibling_combinator

What specific section or headline is this issue about?

Additional helpful information

What information was incorrect, unhelpful, or incomplete?

I was trying to find out how to select based on "previous" sibling and could not find that info easily.

Doing a search for "previous sibling selector" pulls up a bunch of outdated StackOverflow pages with a mix of answers

  • not possible
  • use X library/preprocessor
  • (Correct) actually possible now using the :has() pseudo-class

What did you expect to see?

I expected to see an example of how to select the previous sibling and/or a link to the :has() page

something like this:

/* Next sibling selector */
/* Paragraphs that come immediately after any image */
img + p {
  font-weight: bold;
}

/* "Previous sibling selector" using :has() */
/* Paragraphs that come immediately before any image */
p:has(+ img) {
  color: blue;
}

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

No response

MDN metadata

Page report details
  • Folder: en-us/web/css/next-sibling_combinator
  • MDN URL: https://developer.mozilla.org/en-US/docs/Web/CSS/Next-sibling_combinator
  • GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/css/next-sibling_combinator/index.md
  • Last commit: https://github.com/mdn/content/commit/7fa9b134e7a886b47bd8c6e3135ba329ee0ddf09
  • Document last modified: 2024-01-22T12:25:49.000Z

ChrisFloofyKitsune avatar Aug 07 '24 14:08 ChrisFloofyKitsune

This looks like a fun PR. I'll do it tomorrow ;)

estelle avatar Aug 08 '24 07:08 estelle