CSS href style

I have href with class="button"

I am trying to create a style like this:

 .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 doesn't it work? how to set stye for href with this class ( class="button" )

+6
source share
5 answers

.button 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 .

+15
source

.button a{} is the rule for

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

a.button{} is the rule for

 <a href="" class="button">foobar</a> 
+11
source

please also share html markup.

is a button attribute of a class of an anchor element or is a descendant tag of an element with a class of button ?

if its the first case, use

a.button:link { } etc.

if later, your code is correct

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

Because you said:

"A element with a pseudo-class :blah , which is a descendant of any element

Do you want to:

 a.button:link { /* etc */ 
0
source

Source: https://habr.com/ru/post/887113/


All Articles