Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML: how to set link colors only for specific class

I just saw this question Don't change link color when a link is clicked and now I'm stuck.

I have multiple links on my page, some of them with class="menuLink". Now only for those I want to set the colors different as a normal link. If I would just use

a:link { color:green}
a:hover { color:red }
...

this would apply to all links. But neither

.menuLink:link {color:green} 
//I think because the css "doesn't know" that this class is used for links

nor

.menuLink a:link {color:green}

work. How can I achieve this?

like image 249
Valentino Ru Avatar asked Dec 01 '22 05:12

Valentino Ru


2 Answers

You were close.

a.menuLink:link { color: green; }

Was what you intended to achieve. But try this:

a.menuLink { color: green; }

Would mean a a with a classname of menuLink, the :link is redundant.


.menuLink a:link

Would mean a inside of an element with a classname of menuLink.

like image 109
Madara's Ghost Avatar answered Dec 04 '22 09:12

Madara's Ghost


Have you tried:

   .menuLink {color: green;}
like image 21
Fraggy Avatar answered Dec 04 '22 09:12

Fraggy