Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS a href styling

Tags:

css

i have a href with class="button"

I am trying to style this like that:

.button a:link {text-decoration: none} 
.button a:visited {text-decoration: none} 
.button a:active {text-decoration: none} 
.button a:hover {text-decoration: none; background-color:yellow;color:blue}

why it is not working? how to set stye for a href with that class (class="button")

like image 1000
Joper Avatar asked May 02 '11 11:05

Joper


People also ask

Can I style a href?

Hyperlinks can be styled in many different ways, of course, the color, font-family, background etc. properties do work for links, but they can also be styled according to the state that they are in.

How do I change the color of a href link in CSS?

To change the color of links in HTML, use the CSS property color. Use it with the style attribute. The style attribute specifies an inline style for an element. Use the style attribute with the CSS property color to change the link color.


2 Answers

.button a is a descendant selector. It matches all <a> tags that are descendants of .button.

You need to write a.button:link to match tags that are both <a> and .button.

like image 129
SLaks Avatar answered Oct 02 '22 06:10

SLaks


.button a{} is a rule for

<something class="button">
   <a href="">foobar</a>
</something>

a.button{} is a rule for

<a href="" class="button">foobar</a>
like image 29
tereško Avatar answered Oct 02 '22 06:10

tereško