Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In CSS, want to override my a:link and a:hover directives to for a specific span

Tags:

css

This will probably be a softball for you CSS folks...

I have a site like this:

<div id="header">
<span class="myheader">This is the name of my awesome site!!!!</span>
</div> 
<div id="content">whole bunch of other stuff</div>
<div="sidemenu"><ul><li>something</li><li>something else</li></ul>
<div id="footer">Some footer stuff will go here....</div>

In my css I have some directives to format the hyperlinks:

a:link { text-decoration: none; color : #ff6600; border: 0px; -moz-outline-style: none;}
a:active { text-decoration: underline; color : #ff6600; border: 0px; -moz-outline-style: none;}
a:visited { text-decoration: none; color : #ff6600; border: 0px; -moz-outline-style: none;}
a:hover { text-decoration: underline; color : #000; border: 0px; -moz-outline-style: none;} 
a:focus { outline: none;-moz-outline-style: none;}

Now here is the problem. In my header I have some text that is a link, but I do not want to to format it like all the other links in the site. So basically I want my a:link, a:hover, etc to ignore anything in the "header" div. How can I do this? Assume I need to override this for that div/span?

like image 845
brendan Avatar asked Jan 23 '23 01:01

brendan


1 Answers

You can use syntax like this..

a:link { text-decoration: none; color : #ff6600; border: 0px; -moz-outline-style: none;}
a:active { text-decoration: underline; color : #ff6600; border: 0px; -moz-outline-style: none;}
a:visited { text-decoration: none; color : #ff6600; border: 0px; -moz-outline-style: none;}
a:hover { text-decoration: underline; color : #000; border: 0px; -moz-outline-style: none;} 
a:focus { outline: none;-moz-outline-style: none;}

Then using css inheritance principles you can create more specific rules for links inside the #header element and override any of the properties you like.

#header a:link {  text-decoration: underline; color : #000;  }
#header a:visited {  text-decoration: underline; color : #000;  }

Read about CSS inheritance

like image 75
jessegavin Avatar answered May 25 '23 17:05

jessegavin