Bryan Hadaway's Blog
seattle web design | + share

Use Firefox: Firefox

Your Account:   subscribe

bhadaway@gmail.com | Social: Facebook Twitter LinkedIn Google+
Signup for the Best Hosting Around

Pure CSS Minimalist Image Hover Rollover

Demo:

Code (Only Use ONE of the CSS Methods Below):

CSS Sprites (New Method)

.hov{display:block;width:245px;height:195px;background:url(images/hover.png)}
.hov:hover{background-position:0 -195px}

For this to work, simply stack the normal state image on top of your hover image making one image. They should be exactly the same size and stacked perfectly on top of each other. So in this example the image would be 245×390 pixels.

CSS (Old Method)

.hov{
display:block; 
width:245px; 
height:195px;
background:url(images/hover1.png)}

.hov:hover{
display:block; 
width:245px; 
height:195px;
background:url(images/hover2.png)}

Change the background URL to your image locations and adjust the width and height appropriately.

HTML

<a href="#" class="hov"></a>

Change # to whichever URL you wish.

Avoid Flicker on Image Rollover (Only Necessary for Old CSS Method)

This happens because the second image only loads on mouseover/hover. We can avoid this by preloading the images(s) and this can still be done non-JavaScript with CSS:

CSS

.preload{display:none}

HTML

<img src="images/image2.png" alt="preload" width="0" height="0" class="preload" />

This will preload the images without showing them or messing up your design. Use this method to preload all secondary images (the images to be seen on rollover). This is a much more reliable and lightweight method than the JavaScript alternative.

That’s it. There is certainly more style and techniques you can add, but this is THE most minimal way to create a rollover image effect, if it’s possible to get simpler, let me know.

Enjoy.

Thanks for reading, Bryan

Other Reads:

tagged in , , , ,
Want to share your website, writing, product or service with all my readers too?  
  • Missyjknox

    Hi Bryan, I am having the toughest time getting help with where in PageLines PlatformPro I input the XHTML as noted above

  • http://www.bryanhadaway.com/ Bryan Hadaway

    Hi Missyjknox,

    This article wasn’t created with either WordPress or PageLines in mind.

    However, PageLines’ themes already support dropdown menus natively. Are you having issues getting it to function?

    Thanks, Bryan

Feedback
x close