How to change multiple <a/> tag behavior?

I know I can change the behavior of anchor tags by:

a:link {
    text-decoration: none;
    color: yellow; 
}
a:visited {
    color: yellow;
}

a:hover {
    color: yellow;
}

a:active {
    color: yellow;
}

Open in new window


But if I have more than one set of <a/> tags that I'd want to have different behaviors/colors for, how would I do it?

Thanks.
elepilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bigeven2002Commented:
Hello,
There are a couple ways you can do it.  If the parent tag that has the anchor tag within it has a class defined, then you can modify the CSS to put the class before a:link, etc.

http://jsfiddle.net/bp8scs3a/2/

The fiddle above shows an example of two common ways.

HTML
<p class="p1">
    <a href="#1">Link 1</a> <br />
    <a href="#2">Link 2</a> <br />
</p>

<p>
    
    <a href="#3" class="link1">Link 3</a> <br />
    <a href="#4" class="link1">Link 4</a> <br />
    
    
</p>

Open in new window

CSS
/*  specify a tag class.  a:link will respond only to the tag with the p1 class.
*/

.p1 a:link {
    text-decoration: none;
    color: red; 
}

.p1 a:hover {
    color: yellow;
}

/* No class tag prepended means this will apply to all anchor tags */

a:visited {
    color: blue;
}

/* Specify a class for the anchor tag itself  */

a.link1:hover {
    color: purple;
}

a.link1:active {
    color: green;
}
                                  

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elepilAuthor Commented:
Thank you very much for your help, bigeven2002!
0
bigeven2002Commented:
Certainly, glad I could help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.