首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

:root

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

代码语言:javascript
复制
/* Selects the root element of the document */
/* <html> in the case of HTML */
:root {
  background: yellow;
}

语法

代码语言:javascript
复制
:root

实例

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

代码语言:javascript
复制
:root {
  --main-color: hotpink;
  --pane-padding: 5px 42px;
}

规范

Specification

Status

Comment

Selectors Level 4The definition of ':root' in that specification.

Working Draft

No change

Selectors Level 3The definition of ':root' in that specification.

Recommendation

Initial definition

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

1

(Yes)

1.0 (1.7 or earlier)

9

9.5

1.0

Feature

Android

Edge

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

?

(Yes)

?

?

?

?

扫码关注腾讯云开发者

领取腾讯云代金券