Discussing the nuts and bolts of software development

Friday, June 27, 2008


Pure CSS Image Rollover without background-image

The other day I was in a situation where I had an image that changed to another image when the user mouses over it. Usually I will do this in one of two very standard ways:

Unfortunately, neither of these solutions were optimal as I was looking for a pure-CSS solution (so no javascript) and needed the image to have its own <img> tag (so no background-image). After playing around with my selectors a little, I came up with this little gem:

<div class="buttonContainer">
<img class="rest" src="link_rest.png" />
<img class="roll" src="link_roll.png" />
The CSS:
div.buttonContainer img.roll {
display: none;
div.buttonContainer:hover img.roll {
display: inline;
div.buttonContainer:hover img.rest {
display: none;

This neat CSS trick leaves the images in the html and changes the image on rollover with minimal mark-up. It works by abstracting the :hover pseudoClass to the container, loading both images into the page, and controlling the rollover effect using the images' display attribute.

One word of caution: some older browsers (I'm looking at you, IE6) have poor support for the :hover pseudoclass, which renders this example ineffective; thus if you're supporting a lot of legacy browsers, this may not be for you. However, if you need a rollover that uses actual image tags and want to avoid using javascript, this may be just what you need.

I think this sounded clever, so I have tried it in IE 7.
But I cannot make it work.
Can anyone else?
CSS hover effects gives us the ability to animate changes to a CSS property value. In your lesson we are going to follow that up with different kinds of effects. It is specifically built for use with images. However these effects can make your site feel much more dynamic and alive. The effects will be using today all use code that is supported by modern browsers. Dullness is the opposite of transparency. It’s allowing no light to pass through. You can create transparent images in CSS with the dullness property.
Layering images over one another is a great way to give an Image a new Look. Here the CSS code that display text on image while mouse hover. You can fit all graphics for your whole site in one sprite. If you are feel like doing all the pixel calculations for background positioning. You would still need to give each button its own class name. Since each button would have different position inside the sprite itself.
If you are more like to write for your coming projects. Then you can find a best writing support by finding the service from the online and understand them. A genuine service will always keep best essays and essay writing guidelines for their customers. Try to read the website review of preferred site before going for offering your essay works. So some online service will provide website genuine reviews for understanding the customer. So find that kind of service and then try to read it and understand it very well. This will assist you to select a best essay service for your academic’s writing works.

Examine this page for some useful tips on how to write dissertation cite. Good luck with that in the future
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?