答:悬停不工作(a:hover not working)

2019-06-23 11:02发布

HTML

 <table width="100%">
<tr>
    <td width="90%"></td>
    <td><a href="#" id="logout"><strong>Logout</strong></a></td>
 </tr>
</table>

CSS

@charset "utf-8";
/* CSS Document */

#logout {
color:#BBB;
}

a:hover {
color:#FFF;
}

虽然注销的颜色似乎是什么在给定的CSS,当我把我的鼠标在链接上(白色)的颜色没有变化。 是什么原因 ?

我必须告诉有倾向于改变链接的颜色,当鼠标放在他们,他们做工精细等css文件。

Answer 1:

ID选择( #logout )更具体然后类型选择( a ),加上一个伪类( :hover ),所以你的第一规则集将永远赢得级联 。

使用#logout:hover代替。



Answer 2:

简化:

您有适用于这种定位的两个CSS规则。

这两个规则改变颜色。

只有一个规则可以适用; 只有一种颜色可以被选择。

该浏览器具有基于ID(规则之间作出选择#logout )和基于元素类型(规则<a> )。

基于ID的规则赢在这种情况下。 它更具体指定一个ID比指定类型(锚)的所有元素。



Answer 3:

你必须遵循一个层次序列:

链接,悬停,访问

例如:

a:link
{
text-decoration:none;
color:#008b45;
}

a:hover
{
margin-bottom: 3px solid #ff7400;
    background:white;
}

a:visited
{
color:#ee9a00;
}


文章来源: a:hover not working
标签: html css hover