Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • One image changes to another, on hover

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 430
    Comment on it

    Hello, readers.

    This blog post will tell you how to get one image in place of the other on hover. The height and width of the images are 100% and the position is given absolute. Due to this, one image appears behind the other. The second thing to do is changing the opacity of the top image on hover.

    HTML :

    <div id="parentdiv">
        <img class="bottom" src="two.jpg" />
        <img class="top" src="one.jpg" />
    </div>

    CSS :

                   #parentdiv{
    		  position:relative;
    		  height:281px;
    		  width:450px;
    		  margin:0 auto;
    		}
    
    		img{
    		    border: 0 none;
    		    height: 100%;
    		    width: 100%;
    		    vertical-align: middle;
    		}
    
    		#parentdiv img{
    		     position:absolute;
    		     left:0;
    		     -webkit-transition: opacity 1s ease-in-out;
    		     -moz-transition: opacity 1s ease-in-out;
    		     -o-transition: opacity 1s ease-in-out;
    		     transition: opacity 1s ease-in-out;
    		}
    		
                     .top{
    		    cursor: pointer;
    		}
    
    		#parentdiv img.top:hover{
    		     opacity:0;
    		}

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: