Select Element that Contain a Thing :has()

PHOTO EMBED

Wed Aug 27 2025 12:59:30 GMT+0000 (Coordinated Universal Time)

Saved by @Sebhart #css

/* Selects an h1 heading with a
paragraph element that immediately follows
the h1 and applies the style to h1 */
h1:has(+ p) {
  margin-bottom: 0;
}
content_copyCOPY

Die :has()-Pseudoklasse übernimmt die Spezifität des spezifischsten Selektors in ihren Argumenten auf die gleiche Weise wie :is() und :not().

https://developer.mozilla.org/de/docs/Web/CSS/:has