:only-of-type

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Die :only-of-type CSS-Pseudoklasse repräsentiert ein Element, das keine Geschwister desselben Typs hat.

Probieren Sie es aus

Syntax

css
:only-of-type {
  /* ... */
}

Beispiele

Elemente ohne Geschwister desselben Typs stylen

HTML

html
<main>
  <div>I am `div` #1.</div>
  <p>I am the only `p` among my siblings.</p>
  <div>I am `div` #2.</div>
  <div>
    I am `div` #3.
    <i>I am the only `i` child.</i>
    <em>I am `em` #1.</em>
    <em>I am `em` #2.</em>
  </div>
</main>

CSS

css
main :only-of-type {
  color: red;
}

Ergebnis

Spezifikationen

Specification
Selectors Level 4
# only-of-type-pseudo

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
:only-of-type

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

Siehe auch