How to make image hover in css?

The Solution to How to make image hover in css? is

You've got an a tag containing an img tag. That's your normal state. You then add a background-image as your hover state, and it's appearing in the background of your a tag - behind the img tag.

You should probably create a CSS sprite and use background positions, but this should get you started:

    <a href="home.html"></a>

div a {
    width:  59px;
    height: 59px;
    display: block;
    background-image: url('images/btnhome.png');

div a:hover {
    background-image: url('images/btnhomeh.png);

This A List Apart Article from 2004 is still relevant, and will give you some background about sprites, and why it's a good idea to use them instead of two different images. It's a lot better written than anything I could explain to you.

~ Answered on 2012-04-18 04:17:05

Most Viewed Questions: