transition background images with css3

a refer to previos  post it’s currently not possible to transition background images or css3 gradients!

to avoid using especial per image just using n-th-child  method in css3 !

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

 

Leave a Reply

Your email address will not be published. Required fields are marked *