2015-07-21 90 views
0

我將頁面設置爲三列圖像,並將懸停覆蓋圖添加到它們中。我試圖在主圖像上添加一個額外的覆蓋圖,基本上是一個透明的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> 

回答

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; 
} 
+0

嗯..試圖讓覆蓋png在整個不透明覆蓋層中保持可見。如果我能解決這個問題,還可以使用文本... – damann