Sun, 2013-12-15 17:15
I'm trying to understand CSS specificity, and have read all the info I can find online, but still cannot understand why in the below code, the #RedPlease ID doesn't take priority over h2 and make everything red. I thought ID selectors were more specific than elements (h2 below would fall under this correct?). I'm interested in the reasoning behind why the below example is working the way it is. Thanks for your help and your patience with the super basic nature of this question!
<div id="RedPlease"> <h2>Header Two Why Are You Green?</h2> <p>This is a paragraph. Why is my ID tag not making that header red?</p></div> h2 { background-color: lime; } #RedPlease { background-color: red; }
Sun, 2013-12-15 20:52
#1
Because it's doing what you told it
Specificity is not the issue. The issue is that the background is not inherited. The <p> appears to have a red background because the default value is transparent.
See http://www.w3.org/TR/css3-background/#the-background-color
cheers,
gary
Wed, 2013-12-18 09:46
#2
what a great work.
what a great work.