Using the :root Selector

Description

The :root selector selects the root element in the document. It will always return the html element.

It is introduced in CSS Version 3.

Example

The following code shows the :root selector in use.


<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
:root {<!--   ww w.java2  s  .com-->
  border: thin black solid;
  padding: 4px;
}
</style>
</head>
<body>
  <a href="http://java2s.com">Visit the website</a>
  <p>
    I like <span lang="en-uk" class="class2">CSS</span>.
  </p>
  <a href="http://w3c.org">W3C</a>
</body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    CSS »




CSS Introduction
CSS Background
CSS Border
CSS Box Layout
CSS Text
CSS Font
CSS Form
CSS List
CSS Selectors
CSS Others
CSS Table