html - :hover style on div with an image that doesnt trigger

标签 html css hover overlay pure-css

我一直在尝试用纯css在一个网站上做一个overlay hover的效果

                       <div class="col-md-4 port-show">
                            <img class="img-responsive" alt="" src="">
                            <h2 class=""></h2>
                            <ul>
                                <li></li>
                                <li></li>
                            </ul>
                        </div>

但我遇到了当我将鼠标悬停在 img 上 时不会触发覆盖的问题。我知道我必须以不同的方式来做,但现在不知道怎么做。 CSS:

:hover:after{
        content: "";
        z-index: 10;
        display: block;
        position: absolute;
        height: 100%;
        top: 0;
        left: 0;
        right: 0;
        background: red;
        border-radius: 6px;
        border-color: transparent;
    }

最佳答案

你可以看这里。也许此解决方案会对您有所帮助。

http://codepen.io/anon/pen/VKmxZw

.img-holder {
  position: relative;
  z-index: 1;
  display: block;
  width: 350px;
}
.img-holder img {
  display: block;
  width: 100%;
}
.img-holder:after {
  content: " ";
  width: 100%;
  height: 100%;
  background-color: red;
  z-index: 2;
  left: 0;
  top: 0;
  position: absolute;
  opacity: 0;
}
.img-holder:hover:after {
  opacity: 1;
}
<div class="col-md-4 port-show">
  <span class="img-holder">
    <img src="http://placehold.it/350x150" />
  </span>
  <h2 class=""></h2>
  <ul>
    <li></li>
    <li></li>
  </ul>
</div>

关于html - :hover style on div with an image that doesnt trigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39610278/

相关文章:

html - Sprite 和绝对定位问题 : 2 work and 2 don't?

css - 由其他元素强制悬停 CSS3

javascript - 为什么当我放置更多 DIV 时我的图像会向下移动?

html - 调整手机 Bootstrap 导航栏内的元素大小

c# - 在 Javascript 中设置隐藏的输入值,然后在代码隐藏中访问它

html - 在时事通讯中的多个表格行上显示图像

html - 文本小部件中的图像始终位于不同的行中

javascript - Chartist 饼图,下一行需要标签

javascript - 创建一个javascript函数来隐藏元素?

css - 无法让事件选择器工作