我已经检查了其他问题,但它们不适用于我的情况,我不确定这是否可能。
我将鼠标悬停时需要替换图像。
我不能使用javascript或更改html。我只能使用CSS。
我已经尝试了很多方法,我什至设法做到了这一点,通过使用可见性:隐藏; 在 img 上并在父级上应用背景图像。
但是,它变得毫无用处,因为 img 标签是操作所在的位置。
.HTML
<ul class="or-body-icons ZERO">
<li id="liIconDest-or1">
<img id="iconDest-or1" tabindex="-1" alt="Negócios" src="https://img2.gratispng.com/20180320/bke/kisspng-computer-icons-clip-art-sales-ico-5ab10c441b8ca8.6504430515215524521129.jpg" title="Negócios" style="cursor: pointer" width="16" height="16" border="0">
</li>
</ul>
.CSS
.ZERO {
padding: 0;
margin: 0;
border: 0;
}
#iconDest-or1{
width:150px;
height:100px;
position: relative;
z-index: 1;
}
#liIconDest-or1:hover {
box-sizing: border-box;
background-image: url(https://img2.gratispng.com/20180304/rde/kisspng-ico-pencil-icon-pencil-5a9c43a0652ef3.9860290115201903684145.jpg);
background-size: 320px;
background-repeat: no-repeat;
cursor: pointer;
z-index: 10;
position: relative;
width:320px;
height:320px;
}
ul.or-body-icons li {
list-style-type: none;
float: left;
width: auto;
height: 16px;
line-height: 16px;
margin: 3px 2px;
padding: 0;
}
您可以向 li 元素添加一些 CSS,以便在悬停 li 时隐藏其中的任何图像。这将解决您在悬停时将"可见性:隐藏"应用于 img 的问题:
#liIconDest-or1:hover img {
visibility: hidden;
}
您可以使用悬停伪选择器更改背景图像:
https://jsfiddle.net/moy2010/sgu2jft4/3/
#test {
background-image: url('https://dummyimage.com/600x400/000/fff');
background-size: 100%;
background-repeat: no-repeat;
width: 300px;
height: 300px;
}
#test:hover {
background-image: url('https://dummyimage.com/600x300/000/fff');
}
编辑:
没有注意到您想覆盖来自 img 标签的图像。这是它的更新jsfiddle:
https://jsfiddle.net/moy2010/sgu2jft4/8/