:root
:root CSS 伪类匹配表示文档树的根元素。在 HTML 中,:root 表示 <html> 元素,与选择器 html 相同,不同之处在于它的 特异性 更高。
css
/* Selects the root element of the document:
<html> in the case of HTML */
:root {
background: yellow;
}
语法
css
:root {
/* ... */
}
示例
声明全局 CSS 变量
:root 可用于声明全局 CSS 变量
css
:root {
--main-color: hotpink;
--pane-padding: 5px 42px;
}
规范
| 规范 |
|---|
| 选择器 Level 4 # root-pseudo |
浏览器兼容性
加载中…