...

View Full Version : CSS: Different Styles for Different Links



tomraffe
07-02-2007, 10:44 PM
I have some links which I want controlled by the following CSS which I just use the normal "a href" tag.


a {
color: #1f3d63;
text-decoration: none;
}
a:visited{
color: #1f3d63;
}
a:hover {
text-decoration: underline;
color: red;

Say I wanted some other links to just be white, with perhaps an underline on hover. How would I do this? Creating the CSS isnt the problem, but how would I ensure the link I created is not controlled by the above CSS, but by one telling it to be white with an underline hover.

Jutlander
07-02-2007, 10:48 PM
You make a class. An example.



a.othercolor {
color: #fff;
}

a.othercolor:hover {
color: #fff;
text-decoration: underline;
}


You then just add the class attribute:



<a class="othercolor" href="#">Link text</a>

vexen
07-03-2007, 12:07 AM
if the link has a parent ie. in a div, you could set your whole links inside it being red by example



.redlinks a { color:red }




<div class="redlinks">
<a href="#">a</a>
<a href="#">b</a>
<a href="#">c</a>
<a href="#">d</a>
</div>

Jutlander
07-03-2007, 12:19 AM
That would add a div or even more to the document. Web developers talk about "div-itis" - when there are too many divs on a page.

vexen
07-03-2007, 12:33 AM
That would add a div or even more to the document. Web developers talk about "div-itis" - when there are too many divs on a page.

i was using a div as an example, he could apply it to any parent

tomraffe
07-03-2007, 01:36 AM
Thanks for that. Done well.

VIPStephan
07-03-2007, 01:56 AM
Just noticed vexen’s use of a class name called “redlinks” and wanted to add that it’s not very semantic. You should name classes and IDs according to the function of an element, not it’s supposed look. Looks can change with a new style. The function usually stays. So better call your elements <div class="message"> if you have a couple of boxes with messages or <div id="header"> if you have an element that contains all header stuff of your page.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum