Quantcast
Viewing all articles
Browse latest Browse all 215

CROSSFADING IMAGE HOVER EFFECTS USING HTML AND CSS

Crossfading of images can be done through simple CSS codes and it plays a unique role in displaying images in a website as a gallery or may be as a sideshow.This post is about to teach you how to display another image when you hover the mouse over that image.There are several techniques to implement this hover effect and this post deals in implementing the hover effect using Opacity property of the CSS.Opacity property in CSS was used to define the opaqueness of any object the value ranges from 0 to 1 and it can be given as decimal values too.See how this effect works i this  Demo effects page.Lets see the coding for this cool effect.



CSS CODE:

  1. .bord{
  2.         padding: 0;
  3.         margin: 0;
  4.         -webkit-box-sizing: border-box;
  5.          }
  6. .crossfd{
  7.         background: url("Your second image URL here");
  8.         display: inline-block;
  9.         font:size: 0;
  10.              }
  11. .crossfd img{
  12.                  -webkit-transition: opacity 1s ease-in-out;
  13.                  -moz-transition: opacity 1s ease-in-out;
  14.                  -o-transition: opacity 1s ease-in-out;
  15.                  transition: opacity 1s ease-in-out;
  16.                     }
  17. .crossfd img:hover{
  18.                     opacity: 0;
  19.                                }
In the above CSS code you can see in line "7" the second image that is to be displayed when hovered was defined as background of the original image in line 18 the opacity of the original image was set to 0 when the image was hovered this results in 100% transperancy of the original image and then the background image will be displayed.Thus overall it will look like a hovering effect.

HTML CODE:
  1. <div class="bord crossfd">
  2. <img src="Your orginal image URL here"></img>
  3. </div>
In the HTML part the orginal image source was placed in the <div> tag with class of "bord crossfd" and thus it enables the image to take up the property of these two CSS classes.By this way you can implement crossfading of images or display another image over an image when mouse hovers.

I hope this effect will be useful for you all.Share this post with others if you like and feel free to post on your comments and views about this post with us.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 215

Trending Articles