-1

I already have this code in my style.css (using wordpress):

a:link, a:visited {
    color: #3088FF;
    text-decoration: none;
}

I want to change the anchor text color, font style, bold etc for categories. How can I override this?

looq
  • 83
  • 6
Lisa Ray
  • 73
  • 1
  • 3
  • 8

3 Answers3

5

If you must overwrite existing styles, use the !important declaration. For example,

.myStyledLink{
    color: #FFF !important;
}
ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
looq
  • 83
  • 6
  • HI, BUT I just wanna apply this anchor text CSS only to that particular anchors, my override CSS shouldnt change actual behavior of CSS.. So, does this !important; can only be used for specific anchor tags..? – Lisa Ray Oct 04 '12 at 16:25
  • You can use a class on the anchors which you want to override the css rules. `MyLinkText` – looq Oct 05 '12 at 09:52
2

Assuming you mean the anchor has inline style already that you wish to override with CSS, use the !important keyword:

<a href="#" style="color: red;">hello</a>​​​​​​​​​​​​​​​​

CSS:

a:link, a:visited {
    color: #3088FF !important;
    text-decoration: none;
}​

Live test case.

This will override all other styles including inline style and if you are worried about cross browser compatibility then you shouldn't: What browsers support "!important"?

Community
  • 1
  • 1
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
  • HI, BUT I just wanna apply this anchor text CSS only to that particular anchors, my override CSS shouldnt change actual behavior of CSS.. So, does this !important; can only be used for specific anchor tags..? – Lisa Ray Oct 04 '12 at 16:28
  • @Lisa for this you will have to add `class="something"` to the anchors you want and have `.something { color: #3088FF !important; }` – Shadow The GPT Wizard Oct 05 '12 at 21:30
2

Identify the ID of the categories widget in your output HTML. Let's say that id="widget-cat", then create a CSS rule as follows to override the link colours within that widget, e.g.

#widget-cat a:link, #widget-cat a:visited  {
    color: #FFF;
}

The use of !important is a very last resort to overriding styles really, and I recommend only ever using that if you need to override CSS rules that can't be made more specific and were written by third-party developers that you have no control over.

cspolton
  • 4,495
  • 4
  • 26
  • 34