【发布时间】:2020-01-21 07:08:55
【问题描述】:
我需要在正常图像悬停时更改背景图像。 (请不要建议我把它放到普通的背景图片中)
我使用 z-index 值尝试过这种方式,但它不起作用。这是fillde 它需要预加载图像,因此用户根本看不到图像加载。
img{
width: 120px;
position: relative;
z-index: -1;
}
img:hover{
background-image: url('https://i.ibb.co/bsQL6SK/media13-3-blue.png');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
<img src="https://cdn.freebiesupply.com/logos/large/2x/fox-news-logo-png-transparent.png" alt="">
【问题讨论】:
-
我很好奇是什么让您认为背景图像会通过图像显示?你做什么z-index都没有关系。这是一个......等待它......背景图片。根据定义,它位于内容的后面,而内容恰好是……图像。这就是“背景”的意思。
标签: javascript jquery html css