【发布时间】:2019-02-06 02:18:18
【问题描述】:
我检查了其他问题,但它们不适用于我的案例,我不确定是否可行。
我需要在悬停时替换图像。
我无法使用 javascript 或更改 html。我只能使用 CSS。
我已经尝试了很多方法,我什至设法做到了,通过使用 visibility: hidden;在 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;
}
【问题讨论】:
标签: css css-selectors