Forum Moderators: not2easy

Message Too Old, No Replies

seeking CSS specificity clarification

two different selectors with the same score dominated by earlier . . .

         

mmloseke

10:07 pm on Apr 23, 2008 (gmt 0)

10+ Year Member



Let's say I have some markup like so:

<div id="header">


<ul>
<li>item a</li>
<li>item b</li>
</ul>


<div id="site_nav">
<ul>
<li>item a</li>
<li>item b</li>
</ul>
</div>


</div>

and if I have some css:


#header ul{
border:1px solid blue;}


#site_nav ul{
border:1px solid red;}

So there's two unordered lists here: one directly inside of #header, and another that's inside of #site_nav - which is also inside of #header.

These both have the same CSS specificity score (101, right?) So why is it the case, what rule is being employed, that makes it so the declaration for #header ul overrides the more localized declaration of #site_nav ul? Why does the border render as blue?

Tourz

10:26 pm on Apr 23, 2008 (gmt 0)

10+ Year Member



Works with correct colours for me in IE7 and FF.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#header ul {
border:1px solid blue;
}
#site_nav ul {
border:1px solid red;
}
</style>
</head>
<body>
<div id="header">
<ul>
<li>item a</li>
<li>item b</li>
</ul>
<div id="site_nav">
<ul>
<li>item a</li>
<li>item b</li>
</ul>
</div>
</div>
</body>
</html>