
:root 这个 CSS 伪类匹配文档树的根元素。对于 HTML 来说,:root 表示 <html> 元素,除了优先级更高之外,与 html 选择器相同。
在线示例
设置HTML文档的背景色:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>大卫编程网(div.cn)</title>
<style>
:root
{
background:green;
color:#fff;
}
</style>
</head>
<body>
<p>第一个段落。</p>
<p>第二个段落。</p>
<p>第三个段落。</p>
</body>
</html>测试看看 ‹/›定义和用法
:root
:root选择器用匹配文档的根元素。
在HTML中根元素始终是HTML元素。浏览器兼容性
表格中的数字表示支持该属性的第一个浏览器版本号。
| 选择器 | |||||
|---|---|---|---|---|---|
| :root | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |