One of the messiest things I have seen is the auto-generated code from Dreamweaver for rollover images. It got me thinking of ways to make the images swap without the need of Javascript. Instantly I thought CSS. It was actually fairly simple to get working.
Take for example this button:
Right now the button doesn’t do a thing. However, if we apply some CSS to it, we get a nice button with a rollover.
.button{
background:url('url/to/image.png') no-repeat;
width:20px;
height:20px;
display:block;
}
.button:hover{
background:url(url/to/rollover.png) no-repeat;
}
Now the button will show the image and swap to the rollover when you hover over it. All without Javascript. But, you ask “How do you preload the images without Javascript?”
I laugh, such a simple answer. Put the rollover images at the top of the page, inside of a hidden div.
And there you have it, JS free rollover images.