:root
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since Juli 2015.
Die :root CSS Pseudo-Klasse entspricht dem Wurzelelement eines Baums, der das Dokument darstellt. In HTML stellt :root das <html>-Element dar und ist identisch mit dem Selektor html, mit der Ausnahme, dass seine Spezifität höher ist.
css
/* Selects the root element of the document:
<html> in the case of HTML */
:root {
background: yellow;
}
Syntax
css
:root {
/* ... */
}
Beispiele
>Deklaration globaler CSS-Variablen
:root kann nützlich sein, um globale CSS-Variablen zu deklarieren:
css
:root {
--main-color: hotpink;
--pane-padding: 5px 42px;
}
Spezifikationen
| Specification |
|---|
| Selectors Level 4> # root-pseudo> |
Browser-Kompatibilität
Loading…