在线文档教程
CSS

:root

:root

该:rootCSS伪类与表示该文档的文档树的根元素相匹配。在HTML中,:root表示<html>元素,并且与选择器html相同,只是其特异性更高。

/* Selects the root element of the document */ /* <html> in the case of HTML */ :root { background: yellow; }

语法

:root

实例

:root 可以用于声明全局CSS变量:

:root { --main-color: hotpink; --pane-padding: 5px 42px; }

规范

SpecificationStatusComment
Selectors Level 4The definition of ':root' in that specification.Working DraftNo change
Selectors Level 3The definition of ':root' in that specification.RecommendationInitial definition

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support1(Yes)1.0 (1.7 or earlier)99.51.0

FeatureAndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support?(Yes)????