开发者

Help me understand odd CSS behaviour!

开发者 https://www.devze.com 2023-01-22 04:07 出处:网络
Odd CSS behavior. When i set the visited color using CSS(a.nav:hover as below example) then the hover doesn\'t work once the link is visited by the user. However when i set it with the reference of t

Odd CSS behavior. When i set the visited color using CSS(a.nav:hover as below example) then the hover doesn't work once the link is visited by the user. However when i set it with the reference of the parent element(.header a.nav:hover as below开发者_高级运维) it works. why ?

a.nav:visited{
color:yellow;
}

/*once the link is visited by user this rule not working*/
a.nav:hover{
color:red;
}

/*if we use this rule it works even after the link is visited*/
.header a.nav:hover{
color:red;
}

<div class="header">
<a class="nav" .. >test </a>
</div>


It sounds like a specificity issue. Do you have any other a pseudo-selectors in your CSS? If there's a selector which is more specific than a.nav:hover (such as .header a.nav:hover) then it will override it, regardless of its position in the file.


a.nav:hover,
a.nav:visited:hover{
color:red;
}

or

a.nav:hover{
color:red !important;
}

Should make it work.

0

精彩评论

暂无评论...
验证码 换一张
取 消