views:

55

answers:

2

Please refer to the image at:

http://i50.tinypic.com/svgg2h.jpg

I have defined CSS color(#000000) for my anchor tag inside a table. But that color is overriden by the color value of #content (#50922c) . How can I solve this problem?

+3  A: 

Prepend #content: #content table.grid thead tr.navigation td div.navigator a {}

Selectors with ids in them have higher precedence than those without. The anchor is selected by both of those rules, so make the second one just like the first, but with more detail, adding greater specificity, and thus greater precedence.

See the CSS specification on specificity to see how precedence is calculated.

Anonymous
A: 

Try this:

<style>
  .mycolor {color:#000000 !important};
</style>

<a href="whatever.html" class="mycolor">Hello There</a>

The !importnat declaration overrides all css rules with current one.

Sarfraz
That's not good form because it can override user stylesheets, which is unnecessary and annoying. And it's not valid, anyway.
Anonymous
I concur that !important declarations are a bad idea, because there seriously impair maintenance. If you have 15 CSS files averaging over 1000 lines of code the codes needs to be maintainable.
@austin: but over here we are specifically overriding one class element under the issue not anything else or any other css styles.
Sarfraz
@Sarfraz: The issue is precedence, and can easily be corrected by extending their current selector with greater specificity. You don't need a sledgehammer to cut a pie, even though that will get some of it out of the pan.
Anonymous
(The valid form is `.mycolor { color: #000000 !important; }`)
Anonymous
@Anonymouse: thanks buddy, fixed it.
Sarfraz
One instance of a !important declaration can seriously alter maintenance of bloated code on an enterprise scale because of the codes cascading behavior. This means most of the code is impacted by other code with or without intention to do so and that impact is often not known or realized considering different contexts of multiple css files being sourced into various different pages.