I have an simple image like this:
<img src="/assets/missing.png">
Now what I want is to be able to hover over the image and have a transparent black overlay appear with a big 'x' on it. Is it possible with CSS3 only or do I need Javascript? And if so how?
I sort of got it to work, but i have an issue that i can't seem to fix. Here's a screenshot:
Screenshot
As you can see there is a part on top missing. Here is my css:
.image {
padding: 0px;
display: inline-block;
vertical-align: middle;
max-height: 150px;
max-width: 150px;
margin: 15px;
position:relative;
}
.image img {
width:100%;
vertical-align:top;
}
.image:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.6);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.image:hover:after {
opacity:1;
}
Take a look at following fiddle. I hope it can help. http://jsfiddle.net/somy_taheri/93y6hwjk/1/
<html>
<div class="outer">
<img src="http://placekitten.com/g/200/300">
<div class="overlay">
<p class="text">x</p>
</div>
</div>
</html>
<style>
.outer {
position:relative;
width: 200px;
height: 300px;
}
.overlay {
display: none;
}
.outer:hover .overlay {
display: block;
position: absolute;
width: 100%;
height: 100%;
background: black;
opacity: 0.7;
top: 0;
}
.text {
position: absolute;
top: 50%;
left: 50%;
transform:translate(-50%, -50%);
color:white;
}
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With