In this example:
<style>
/* Default links */
a {
color: #0F0; /* Green */
}
/* Header links */
#header a {
color: #F00; /* Red */
}
/* Login link */
#login {
color: #00F; /* Blue */
}
</style>
<header id="header">
<p><a href="#">header link</a> is red</p>
<p><a id="login" href="#">login link</a> is not blue</p>
</header>
Is not logical that the login link must be blue?
I know that the declarations have the same origin and same importance, so they need to be scored (selector's specificity).
To calculate selector specificity I created an table for each selector:
A = Number of inline styles: 0
B = Number of ID: 0
C = Number of classes: 0
D = Number of elements: 0
So the login element have 3 collisions related to his color: a, #header a, #login
element (A, B, C, D)
a (0, 0, 0, 1) = 1
#header a (0, 1, 0, 1) = 101
#login (0, 1, 0, 0) = 100
The selector "#header a" wins because it had the biggest score.
But
If we change the selector "#login" to "a#login", we will have:
a#login (0, 1, 0, 1) = 101
The selector "#header a" looses, because with a draw wins the last that was declared.
So, the thing that I can't understand is:
Since "#header a" selector refers to many elements and an ID selector (e.g. #login) just refer one element, is logical that we want to apply ID selector declarations to that element, right? I really can't understand this CSS precedence logic, because I think ID selector must be basically the most specific thing possible, just like inline styles.
P.S.: Sorry for my bad english :)