对于网站上的一些不错的链接,我使用伪类 a::hover 和伪元素 a::after:
a {
position: relative;
display: inline-block;
outline: none;
color: #404d5b;
vertical-align: bottom;
text-decoration: none;
white-space: nowrap;
}
a::hover,
a::after {
pointer-events: none;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-font-smoothing: antialiased;
font-smoothing: antialiased;
}
现在这也适用于插入到链接元素中的图像,如下所示:
<a href="#"><img src="source.jpg" /></a>
如何隐藏图像的这种样式?我不希望他们在悬停时有这个背景......
最佳答案
你可以使用兄弟技巧:
.parent {
width:100px;
height:100px;
padding:50px;
}
.parent:hover {
}
.child {
height:100px;
width:100px;
background:#355E95;
transition:background-color 1s;
position: relative;
top: -200px;
}
.child:hover {
background:#000;
}
.sibling{
position: relative;
width:100px;
height:100px;
padding: 50px;
top: -50px;
left: -50px;
background:#3D6AA2;
transition:background-color 1s;
}
.sibling:hover{
background:#FFF;
transition:background-color 1s;
}
<div class="parent">
<div class="sibling"></div>
<img src="http://www.dunbartutoring.com/wp-content/themes/thesis/rotator/sample-1.jpg" class="child" />
</div>
关于css - a::hover/after 不适用于图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29600511/