我在CSS中设置了悬停效果,但似乎没有效果。我做错了什么?
.button_link {
display: inline-block;
border: solid black 2px;
border-radius: 15px;
background-color: #ddf;
padding: 10px;
text-decoration: none;
}
.button_link#hover {
color: orange;
background-color: #fff;
}

<div><a class="button_link" href="http://example.com">Return to example.com</a></div>
<div class="button_link">aa</div>
&#13;
答案 0 :(得分:2)
#
悬停需要为:hover
那应该解决它
答案 1 :(得分:2)
它无法正常工作,因为您已将选择器编写为:
.button_link#hover,
哪个元素的选择器的类button_link
和id
的{{1}};而你想用hover
伪类来定位类button_link
的元素,因此:
:hover
.button_link:hover
.button_link {
display: inline-block;
border: solid black 2px;
border-radius: 15px;
background-color: #ddf;
padding: 10px;
text-decoration: none;
}
.button_link:hover {
color: orange;
background-color: #fff;
}
参考:
答案 2 :(得分:2)
因为你需要写:
.button_link:hover {}
答案 3 :(得分:2)
.button_link {
display: inline-block;
border: solid black 2px;
border-radius: 15px;
background-color: #ddf;
padding: 10px;
text-decoration: none;
}
.button_link:hover {
color: orange;
background-color: #fff;
}
<!DOCTYPE html>
<html>
<div><a class="button_link" href="http://example.com">Return to example.com</a></div>
<div class="button_link">aa</div>
</html>
您好,您应该将 button_link #hover 更改为 button_link:hover 。 快乐的编码!
参考: CSS伪类