Specificity

Given that it is possible to use multiple stylesheets in an HTML document it is inevitable that sooner or later the same CSS selector will be inconsistently defined in different stylesheets. In such situations the browser will apply the CSS rule that has the greatest specificity to the context at hand. Specificity is a complex subject and much has been written on it. The example below illustrates some of the subtleties involved

Some text and an anchor
Some text and an anchor
Some text and an anchor
<html>
<head>
<style>
div{color:red}
div{color:blue}
.one{color:black}
.one a{color:fuchsia}
a{color:maroon}
</style>
</head>
<body>
<div>
Some text and an <a href="anchor.html">anchor</a>
</div>
<div class="one">
Some text and an <a href="anchor.html">anchor</a>
</div>
<div class="one" style="color:gray">
Some text and an <a href="anchor.html">anchor</a>
</div>
</body>
</html>
Jump To...

Colophon