我有这个示例代码,它悬停图像以更改背景颜色。悬停时如何用颜色填充整个图像?
在我的代码片段中,它只填充 a 标签元素的背景颜色,而不是图像。
这是进一步澄清我的问题的图像。
如何使用标签元素中的悬停效果来实现这一点。
a img:hover {
background-color: purple;
}
a:hover {
background-color: yellow;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!-- Hovered with image no text -->
<a href="https://www.w3schools.com"><img src="cart.png"></a>
<!-- Hovered without image just text -->
<a href="http://www.wikipedia.org">Change color text</a>
</p>
</body>
</html>
我找到了另一种更改背景图像的方法。我想有两个图像,所以当悬停时它会改变图像。感谢您的信息@Jaromanda X
#my-img:hover {
content: url('images/pinkcart.png');
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img id="my-img" src="images/redcarticon.png"/>
</p>
</body>
</html>
也感谢大家对我的帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句