简介
:root伪类匹配文档树的根元素。应用到HTML,:root 即表示为<html>元素,除了优先级更高外,相当于html标签选择器。
语法
:root { 样式属性 }
例子
使用:声明全局CSS变量时:root很有用:
:root {
--main-color: hotpink;
--pane-padding: 5px 42px;
}
规范
| Specification | Status | Comment |
|---|---|---|
| Selectors Level 4 :root |
Working Draft | No change |
| Selectors Level 3 :root |
Recommendation | Initial definition |
浏览器兼容性
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 1 | 1.0 (1.7 or earlier) | 9 | 9.5 | 1.0 |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | ? | ? | ? | ? | ? |