How does CSS determine when to apply one style over another?
I have been through the W3 CSS3 selectors document a few times, and that has helped me understand how to better use CSS selectors in jQuery, but it has not really helped me understand when one CSS rule will be applied over another.
I have the following the HTML:
<div class='item'>
<a>Link 1</a>
<a class='special'>Link 2</a>
</div>
I have the following CSS:
.item a {
text-decoration: none;
color: black;
font-weight: bold;
font-size: 1em;
}
.special {
text-decoration: underline;
color: red;
font-weight: normal;
font-size: 2em;
}
Given the above, both Link 1 and Link 2 will be styled the same, as determined by the .item a
CSS. Why does the style associated with .special
not take precedence for Link 2?
Obviously, I can get around it like this:
.special {
text-decoration: underline !important;
color: red !important;
font-weight: normal !important;
font-size: 1em !important;
}
But, I feel like that is a hack that I have to sprinkle in due to my lack of understanding.