JSFiddle - React, Tailwind, and code Playground
HTML
<div class="images-container">
<img src="http://lorempixel.com/400/200/animals/9/">
<img src="http://lorempixel.com/400/200/animals/10/">
</div>
CSS
div{
position: relative;
width: 400px;
height: 200px;
}
div > img{
display: block;
width: 400px;
height: 200px;
position: absolute;
/* transitions */
-webkit-transition: all .4s ease;
-moz-transition: all .4s ease;
-ms-transition: all .4s ease;
-o-transition: all .4s ease;
transition: all .4s ease;
}
/* solution 1: css3 solution, it depends of <img>'s order */
div > img:nth-child(1){ /* first <img> child of <div> */
filter: alpha(opacity=100); /* IE stuff */
opacity: 1;
z-index: 2;
}
div > img:nth-child(2){ /* second <img> child of <div> */
filter: alpha(opacity=0); /* IE stuff */
opacity: 0;
z-index: 1;
}
/* hover */
div:hover > img:nth-child(1){
filter: alpha(opacity=0);
opacity: 0;
z-index: 1;
}
div:hover > img:nth-child(2){
filter: alpha(opacity=100);
opacity: 1;
z-index: 2;
}