Typselektoren

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.

Der CSS Typselektor wählt Elemente nach ihrem Knotennamen aus. Mit anderen Worten, er wählt alle Elemente des angegebenen Typs innerhalb eines Dokuments aus.

css
/* All <a> elements. */
a {
  color: red;
}

Typselektoren können bei der Verwendung von @namespace mit Namespaces versehen werden. Dies ist nützlich, wenn man mit Dokumenten arbeitet, die mehrere Namespaces enthalten, wie HTML mit eingebettetem SVG oder MathML, oder XML, das mehrere Vokabulare mischt.

  • ns|h1 - wählt <h1> Elemente im Namespace ns
  • *|h1 - wählt alle <h1> Elemente
  • |h1 - wählt alle <h1> Elemente ohne einen deklarierte Namespace

Syntax

css
element { style properties }

Beispiele

CSS

css
span {
  background-color: skyblue;
}

HTML

html
<span>Here's a span with some text.</span>
<p>Here's a p with some text.</p>
<span>Here's a span with more text.</span>

Ergebnis

Namespaces

In diesem Beispiel wird der Selektor nur <h1> Elemente im Beispiel-Namespace ansprechen.

css
@namespace example url(http://www.example.com/);
example|h1 {
  color: blue;
}

Spezifikationen

Specification
Selectors Level 4
# type-selectors

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
Type selector (elementName)
Namespaces (ns|elementName)

Legend

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

Full support
Full support

Siehe auch