语法

:root {
  css declarations;
}

:root 伪类示例:

<!DOCTYPE html>
<html>
  <head>
    <style>
      :root {
        background-color: #8ebf42;
        padding: 2em;
      }
      body {
        background-color: #eee;
        padding: 1.5em;
      }
    </style>
  </head>
  <body>
    <h2>:root selector example</h2>
    <p>生活终归还得继续。</p>
  </body>
</html>
CSS :root 伪类

:root 伪类选择代表文档根的元素。

在 HTML 中,根元素始终是 <html>。

在 SVG 和 XML 中,:root 伪类可以引用更高级别的祖先。

:root 伪类可以与伪元素(例如 ::after)和其他伪类(例如 :hover)链接。

日期:2020-06-02 22:14:45 来源:oir作者:oir