Consider the following example: http://jsfiddle.net/j6SpZ/
HTML:
<div class="container"> <a>Foobar</a> <a class="pink">Pink</a> <a class="gray">Gray</a> </div>
CSS
a { border: 1px solid black; padding: 20px; display: block; } a.gray { background-color: gray; } a:hover { background-color: teal; } .container a { background-color: transparent; } a.pink { background-color: pink; }
Result:

So, everything happens according to the specification.
The style priority values for the last four selectors are all (0,0,1,1): 1 class + 1 element. You get the expected transparent background for the first and third fields (even when hovering), because .container a appears after a.gray and a:hover . You turn pink on the second because a.pink appears after .container a . Cool (if I misinterpreted the spec, let me know, but I think I'm for the money).
But my question revolves around the semantics of resolving selectors on parent elements, which have the same impact on specificity as selectors on a modified element. I believe that the gray class selector is definitely “closer” and more specific to the element than the container class selector for the parent element and that the a.gray style a.gray should have higher priority.
Is there a way to do this this way, or a philosophy that I can follow to resolve the dissonance in my thoughts?
Actual application:
I have a select button style that makes up the following:
.options a { background-color: gray; } .options a:hover { background-color: blue; }
In principle, the selection buttons are gray and blue on hover. Now I want to put them in a special area where I want the default behavior to have a transparent background:
.env1 .subenv1 .options a { background-color: transparent; }
But now this announcement has priority even over :hover , and I do not want this. I still want his guidance behavior to be the same; I just want the default background to be transparent. Of course, I can redeclare hover styles, but this repeats that information which is unideal. I have no problem sucking it and just re-announcing, this is what I am doing right now, but of course there must be a way to make this make sense in my head.