【发布时间】:2018-01-17 08:32:12
【问题描述】:
所以我一直在研究一个带有可点击图像的网站,但我似乎无法正确获取...:hover。我希望图片被白色覆盖,不透明度为 0.1。
<html>
<head>
<style>
body {padding: 0; margin: 0;}
img {
margin-top: -10px;
width: 100%;
height: auto;
}
a:hover {
background-color: rgba(255, 255, 255, 0.1);
}
#asca:hover {background-color: rgba(255, 255, 255, 0.1);}
#fhca:hover {background-color: rgba(255, 255, 255, 0.1);}
#asca img:hover {background-color: rgba(255, 255, 255, 0.1);}
#fhca img:hover {background-color: rgba(255, 255, 255, 0.1);}
</style>
</head>
<body>
<a id="asca" href="asc.php">
<img src="Pictures/chevcorvette4kp.png" width="4096" height="900" alt="ascpic">
</a>
<a id="fhca" href="fhc.php">
<img src="Pictures/fhyper.png" width="4096" height="900" alt="fhcpic">
</a>
</body>
</html>
如您所见,我确实尝试在悬停时将所有内容更改为该颜色,但似乎不起作用。
【问题讨论】:
-
当然不行,因为你实际上还没有在图像前面“覆盖”任何东西——你只是在改变背景颜色在之后图片。您需要先在图像顶部放置一个(伪)元素,然后您可以修改该元素的背景。
标签: html css image hover background-color