html - 使用悬停时图像不显示
问题描述
当我将鼠标悬停在图像上时,我试图将图像更改为另一个图像,但屏幕上什么都没有出现,我很困惑。HTML 和 CSS 在同一个文件中。一切都在一个名为“海象”的文件夹中,在该文件夹中是 html/css 编码和一个名为“图像”的图像文件夹。
这是代码:
<style>
.b-george {
width: 130px;
height: 195px;
background: url("images/beatlegeorge.jpg") no-repeat;
margin: 50px;
}
.b-george:hover {
background: url("images/george.jpg") no-repeat;
}
</style>
<div class="b-george"></div>'
解决方案
您需要background-size
为该元素提供值:
background-size: 130px 195px;
.b-george {
width: 130px;
height: 195px;
background: url("https://www.netclipart.com/pp/m/1-15005_animals-clipart-png-cartoon-animals-png-cute-animal.png") no-repeat;
margin: 50px;
background-size: 130px 195px;
}
.b-george:hover {
background: url("http://pluspng.com/img-png/animal-png-i-absolutely-love-tigers-and-have-two-of-my-own-on-my-tattoos-347.jpg") no-repeat;
background-size: 130px 195px;
}
<div class="b-george"></div>
推荐阅读
- go - 从golang中的索引PNG文件中获取像素颜色编号
- python - 从文件执行时解决 ModuleNotFoundError
- scala - 如何真正测试akka流?
- c++ - 设置边框出现在多边形区域外 cocos2d-x
- c++ - 从文件中填充结构数组
- if-statement - 尝试在条件格式公式中使用 IF VLOOKUP 并获取无效公式
- r - 在 R 中,不应该修改具有单一名称绑定的对象保留其内存地址吗?
- javascript - 断开连接后我无法连接到 Socket.io 房间
- python - 为什么这棵决策树在每一步的值不等于样本数?
- javascript - 是否可以通过“谷歌浏览器”中的 url/js/php 执行程序?