I want the words of my link to be red and the underline to show up only when it's hovered, and this is my code:
a:hover div {
text-decoration: underline;
}
a div{
color: red;
text-decoration: none;
}
<a href="">
<div>next page</div>
</a>
Now the color of the text is red but the underline doesn't disappear. Why?
答案 0 :(得分:1)
试试这个,只需为text-decoration:none
设置a tag
。
a{
color: red;
text-decoration: none;
}
a:hover div {
text-decoration: underline;
}
a:hover div {
text-decoration: underline;
}
a{
color: red;
text-decoration: none;
}
&#13;
<a href="">
<div>next page</div>
</a>
&#13;
答案 1 :(得分:1)
您不能在内联项(div
)中包含块级项(a
)。因此,尚不支持它的浏览器可能会将div
从a
中删除。相反,使用span
并向display: block
提供a
,同时block
或inline-block
中有a {
color: red;
text-decoration: none;
}
a:hover div {
text-decoration: underline;
}
。
但对于支持此行为的浏览器,您的解决方案将在以下代码段中填写:
<a href="">
<div>next page</div>
</a>
&#13;
Math.abs(mMatrixValues[Matrix.MSCALE_X]);
&#13;
答案 2 :(得分:1)
下划线不是由于div中的样式。这是a标签的默认样式。删除css选择器中的div部分:
a:hover {
text-decoration: underline;
}
a {
color: red;
text-decoration: none;
}
<a href="">
<div>next page</div>
</a>