简体   繁体   English

将鼠标悬停添加到图像上

[英]Adding an overlay to an image with a hover

I have the page set up as three images in columns with a hover overlay to them. 我将页面设置为列中的三个图像,并将它们悬停在它们上面。 I am trying to add an additional overlay to them, basically a transparent png, over the main image but before the hover overlay. 我正在尝试在主图像上但在悬停覆盖之前向其添加一个附加覆盖,基本上是透明png。

Here is my code and I am having issues figuring it out. 这是我的代码,我在解决它时遇到了问题。

fiddle: http://jsfiddle.net/r4mp0v4v/ 小提琴: 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>

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

I removed some stuff just so I could see your code better. 我删除了一些东西只是为了更好地查看您的代码。

.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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM