CSS Image Rollover Effects

Blogged in Web Design, Internet by Matt on Tuesday November 29, 2005

Note: This is a technique to develop CSS Image Rollovers, however it isn’t the most effective nor correct, for a more indepth, correct technique please use the following to create CSS Image Rollovers.

So I’ve been working on a layout for a website a couple of guys and I are putting together to sell independent games online with. I, myself tend to try and stick with XHTML when designing a site. I’ve heard of people creating Image Rollovers using CSS, and decided to try and figure this out myself, and what do you know, I suceeded! Good bye days of using JavaScript to complete such a feature, and hello my good friend Cascading Style Sheets.

The process for creating image rollovers in CSS is simple, and I’m gonna throw the code and technique in here so all who want to see can. If there are any questions drop a comment and I’ll see what I can do for you.

Cascading Style Sheet (CSS) Image Rollover Code

/* This is the Default Button */
div#button a{
font-family: Arial, Helvetica, Verdana;
font-size: 12px;
color: black;
text-align: center;
width: 100px;
height: 20px;
background-image:url(images/button1.jpg);
background-repeat: no-repeat;
}

/* This is the Highlighted Button */
div#button a:hover, div#button a.current{
background-image:url(images/button2.jpg);
color: black;
}

Pop the above code in your style sheet. In this case, create a DIV with the name of “button”. Inside of the DIV named button you will want to put each element you want to have an Image Rollover on inside of an anchor, you know the good ol “a href” tag. Once that’s done, tweak the CSS to your likings, make sure you change the image names to reflect what you are doing, and you’ll be good to go.

Popularity: 23% [?]


4 Responses to “CSS Image Rollover Effects”

grinder Says:

Will this preload the hover image or will it dl it at the time it is hovered?

Matt Says:

No, Javascript still needs to be used to Preload the image, sadly.

Ruined My Life » Image Preloading Script Says:

[…] esign, Programming by Matt Thursday December 1, 2005 In my previous post regarding CSS Image Rollovers there was question asked whether or not the image is prelo […]

Ruined My Life » Correct, Non Preloading CSS Image Rollovers Says:

[…] In a previous post I touched on and provided some code for CSS Image Rollovers. That code worked properly in Internet Explorer, with a pre-loading script. Through doing some more reading and tinkering I’ve decided to share the “best” way to implement the effect for cross browser compatibility. […]

Leave a Reply

Quote selected text