44

In my Page the following CSS is set:

a:link {
    color: #0094DE;
    text-decoration: none;


}
a:visited {
        text-decoration: none;
color: #0094DE;

}
a:hover {
text-decoration: underline;
color: #DD127B;

}

I want to Change the Link color inside a div which has a class assigned to it. I tried the following :

register:link{color:#FFFFFF;
        }

Where register is the name of the div in which i want to change the link color. How can i do that? Also how to change the color for hover link over the same div?

Anil Jain
  • 481
  • 1
  • 4
  • 7

8 Answers8

63
.register a:link{
    color:#FFFFFF;
}
daniel__
  • 11,633
  • 15
  • 64
  • 91
Shehzad Bilal
  • 2,535
  • 2
  • 18
  • 27
  • note that this should be #register, not .register ... the OP said div not class – carrabino Oct 01 '13 at 09:28
  • 3
    @Anthony The OP said div with a class assigned to it. Does what you say still apply? – Nels Beckman Aug 24 '14 at 15:25
  • OP: "Where register is the name of the div in which i want to change the link color" ... which to me says register is the id value, not the name of a class that's been assigned to the div. – carrabino Aug 25 '14 at 19:45
  • This answer doesn't work for multiple users. See https://stackoverflow.com/a/30296997/8314623 for a different solution. – Magiranu Nov 11 '17 at 13:46
51

It can be something like this:

a.register:link { color:#FFF; text-decoration:none; font-weight:normal; }
a.register:visited { color: #FFF; text-decoration:none; font-weight:normal; }
a.register:hover { color: #FFF; text-decoration:underline; font-weight:normal; }
a.register:active { color: #FFF; text-decoration:none; font-weight:normal; }
Aditya P Bhatt
  • 21,431
  • 18
  • 85
  • 104
6

how about something like this ...

a.register:link{
    color:#FFFFFF;
}
6

I think there is a confusion about what the OP is actually asking.

This solution:

a.register:link {color:#FFF}

...changes the color of a link whose class is "register". But that's not what the OP was asking.

And this solution:

.register a:link {color:#FFFFFF;}

...changes the color of a link that itself has no class but is placed inside of a div with class "register". And that's what the OP was asking.

Both of these answers are being upvoted here but only the second one is correct answer to the original question.

fuxoft
  • 154
  • 1
  • 6
  • Thank you for your answer! Make sure you take a look at the other answers in the thread as well before submitting. It looks like this answer is the same as the current top voted but was determined to not be the final working solution. – Adam Apr 27 '21 at 12:23
  • Currently the most upvoted answer is correct and the second most upvoted answer is wrong but it's getting upvoted and praised anyway because it's correct for people who are trying to solve different problem than the OP posed. That's why I posted this to hopefully clear the confusion. – fuxoft Apr 27 '21 at 12:44
3
#register a:link
{
color:#fffff;
}
Prashobh
  • 9,216
  • 15
  • 61
  • 91
3

If you want to add CSS on a:hover to not all the tag, but the some of the tag, best way to do that is by using class. Give the class to all the tags which you want to give style - see the example below.

<style>
a.change_hover_color:hover { 
    color: white !important;
}
</style>

<a class="change_hover_color">FACEBOOK</a>
<a class="change_hover_color">GOOGLE</a>
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
sayyed tabrez
  • 116
  • 1
  • 1
  • 11
0

I think you want to put a, in front of a:link (a, a:link) in your CSS file. The only way I could get rid of that awful default blue link color. I'm not sure if this was necessary for earlier version of the browsers we have, because it's supposed to work without a

César
  • 9,939
  • 6
  • 53
  • 74
-2

smaller-size version:

#register a:link {color: #fff}
Pete
  • 57,112
  • 28
  • 117
  • 166