Forum Moderators: not2easy

Message Too Old, No Replies

CSS3 guide: 3.4. :root pseudo class

         

swa66

9:56 pm on Jun 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a post in a series, please see the Table of Contents [webmasterworld.com] for the other posts in the series.

3.4. root pseudo class

The root pseudo class selector [w3.org] selects the root element.

Syntax: :root

    It applies to the root element (in html this is the <html> element).

    Note it selects the root element with a higher specificity (0.0.1.0) than html would (0.0.0.1)

Example:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>root pseudo class selector test</title>
<style type="text/css">
:root {
background: green;
font-family: Arial, Helvetica, sans-serif;
}
html {
background: yellow;
}
body {
background: red;
}
</style>
</head>
<body>
<p>red bar on green background = ok</p>
<p>red bar on yellow background = lacks support for :root</p>
</body>
</html>

Support:

  • Widely supported in standard compliant browsers
  • Not supported by IE (including IE8)

Graceful fallback:
Style the html for (x)html documents.

Practical use:
With lacking support form all versions of IE, we might as well style <html>, for more generic xml purposes this might be much more useful.
The obvious use of this as a hack is risky at best, and counterproductive in the long run, please use conditional comments instead whenever possible.

swa66

9:30 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



reserved for future use