In this post we will take a look on flipping images using CSS3.0. Let us assume that we have a div with two images as following,
<div id="flipimagediv"> <img id="backImage" src="images/srt.jpg" /> <img id="frontImage" src="images/msdhoni.jpg" /> </div>
Now we want to flip these two images on mouse hover. We will achieve that using CSS3.0. To start with let us set container div style. In container we are setting width, height and display.
#flipimagediv {
display: inline-block;
width: auto;
height: auto;
position: relative;
}
After setting container div styles let us go ahead and set image styles. In image style we are setting usual properties like height and width. We are setting
- transition-property
- transition-duration
- transition-timing-function
#flipimagediv img {
width: 400px;
height: 300px;
position: absolute;
transition-property: opacity;
transition-duration: 3s;
transition-timing-function: linear;
}
Last we need to change opacity of images on hover. We can do that as following.
#flipimagediv #frontImage, #flipimagediv:hover #backImage {
opacity: 1;
}
#flipimagediv:hover #frontImage, #flipimagediv #backImage {
opacity: 0;
}
In this way we can flip images on hover using CSS 3.0. I hope you find this post useful. Thanks for reading.
Pingback: Geek Reading March 12, 2013 | Regular Geek