使用悬停为图像添加叠加层

时间:2015-07-21 16:04:57

标签: html css overlay

我将页面设置为列中的三个图像,并将悬停覆盖到它们。我试图在主图像上但在悬停覆盖之前为它们添加一个额外的叠加层,基本上是透明的png。

这是我的代码,我在解决问题时遇到了问题。

小提琴:http://jsfiddle.net/r4mp0v4v/

.wrapper img{
float:left;
width:100%;
}

@media screen and (min-width: 700px) {
.wrapper img{
    width:33%;
    height:100%;
}
}
body {
  display: block;
  margin: 0px;
}

img:hover{
opacity: 1;

}

img {
opacity: 0.5;
background: #000;
}

overlay_image{
position: absolute;
top: 60px; 
left: 80px;
}

<div class="wrapper">
<a href="Northside.html">
<img src="https://upload.wikimedia.org/wikipedia/commons/6/6d/Good_Food_Display_-_NCI_Visuals_Online.jpg" alt="">
<img src="http://creativitywindow.com/wp-content/uploads/2013/02/PNG-Portable-Network-Graphics.png" class="overlay_image">
</a>
</div>
<div class="wrapper">
<a href="Catering.html">
<img src="https://upload.wikimedia.org/wikipedia/commons/6/64/Foods_(cropped).jpg" alt="">
</a>
</div>
<div class="wrapper">
<a href="test/index.html">
<img src="http://www.healthsguardian.com/wp-content/uploads/2015/05/Improper-time-to-have-some-foods.jpg" alt="">
</a>
</div>

1 个答案:

答案 0 :(得分:0)

像这样:http://jsfiddle.net/r4mp0v4v/1/

我删除了一些内容,以便更好地查看代码。

.wrapper { position: relative; }
.wrapper img{
    width:33%;
}
body {
  display: block;
  margin: 0px;
}
img.overlay_image:hover{
    opacity: 0;
}
img.overlay_image {
    opacity: 0.5;
    background: #000;
}

.overlay_image{
    position: absolute;
    top: 0px; 
    left: 0px;
    width: 100%;
    height: 100%;
    z-index: 5;
}
.main_image{
    position: relative;
    z-index: 0;
}