Given the following mark-up...
<div id="Header">
<a href="#" class="Highlight">foo</a>
</div>
And the following stylesheet...
/******************Exceptions******************/
#Footer, #Header,
#Footer a, #Header a { color: #f8f8f8; }
/******************Classes******************/
.Highlight, a.Highlight { color: #B1D355; }
.Notification, a.Notification { color: Red; }
Why is my link still off-white (F8F8F8) rather than green (B1D355)?
Shouldn't using the class Highlight override the color settings for Header and Footer since it comes after their declarations?
The location order of precedence is: browser default rules, external style sheet rules, embedded styles, and inline style rules.
CSS specificity rule 1) Inline style: Inline style has highest priority among all. 2) Id Selector: It has second highest priority. 3) Classes, pseudo-classes and attributes: These selectors has lowest priority.
The components of css style are: 1)Selecter:HTML element name, id name, class name. 2)Property:It's like an attribute such as background color,font-size,position,text-align,color,border etc. 3)Values:which defines property or values allocate for properties.
It's all about weight. A class selector gets trumped by an ID selector.
#Footer a
will always get precedence over
.Highlight
or .Highlight a
Make your selector
#Footer .highlight a
and you should be fine.
ID selector > class selector > attribute selector
For the same priority, the later has the higher priority.
.class1 { color: black; }
.class2 { color: red; }
It will be red.
To have more priority, use !important
For your problem, #Footer
is an ID selector has higher priority than .Highlight
, a class selector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With