http://jsfiddle.net/AndyMP/T5pX2/
.block {
position: relative;
margin: 25px;
width: 300px;
height: 300px;
border: 1px solid black;
}
.overlay {
width: 300px;
height: 300px;
background: yellow;
opacity: 0;
}
<div class="block">
<div class="overlay">
</div>
</div>
In the CSS, use the @keyframes rule paired with fadeIn. At 0%, set the opacity to 0. At 100%, set the opacity to 1. This creates the fade-in effect.
First, we create a <div> element (class="background") with a background image, and a border. Then we create another <div> (class="transbox") inside the first <div>. The <div class="transbox"> have a background color, and a border - the div is transparent.
You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).
Use animation and transition property to create a fade-in effect on page load using CSS. Method 1: Using CSS animation property: A CSS animation is defined with 2 keyframes. One with the opacity set to 0, the other with the opacity set to 1.
What you have at the moment is not an overlay it's just one div inside another.
To make it an overlay you need to use position:absolute
as follows:
JSfiddle Demo
CSS
.block {
position: relative;
margin: 25px;
width: 300px;
height: 300px;
border: 1px solid black;
padding:1em;
}
.overlay {
background: rgba(0,0,0,0.5);
opacity: 0;
position: absolute;
top:0;
left:0;
width:100%;
height:100%;
transition:opacity 0.5s ease;
}
.block:hover .overlay {
opacity:1;
}
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