css - a::hover/after 不适用于图像

标签 css image hyperlink pseudo-element

对于网站上的一些不错的链接,我使用伪类 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>

查看此答案:https://stackoverflow.com/a/17924223/586051

关于css - a::hover/after 不适用于图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29600511/

相关文章:

jquery - 修复了带有滚动条的菜单滚动并停在顶部

javascript - 简单的可切换 JS 下拉菜单

php - 如何使用php脚本将图像上传到数据库?

python - 如何使用numpy镶嵌数组?

java - 使用java中的CSV writer将文本转换为超链接

css - 我的 Rails 模态窗口在小屏幕上不完全可见

javascript - 无法弄清楚盒子大小、媒体查询或 javascript

WPF - 动画图像源更改

jquery - 模拟链接/按钮点击事件上的 POST

c# - 当 C# 没有任何 ID 和名称时,如何单击 Web 表单上的元素(超链接)