Image Rollovers With CSS

In this tutorial you will learn how to make an CSS rollover effect.

Most of you saw how this effect looks like. When you pass over a, in this case graphic button,

it changes shape,color,text…

It’s not necessary to use a graphic object in this effect, but for purpose of this tutorial I will use a graphic button.

First, you need to create a graphic object which you will use for this effect. You can even use mine if you want to.

rollovergraphic.jpg

This graphic object contains 2 buttons which we will use as a normal state and mouse over state.

They are saved in one file.

Dimensions 80×50 pixels

Why do we use one graphic file instead of two?

Well, if you use two graphic files, one for each state (mouse over, normal), this effect gets a bit slower because one graphic, which shows as a normal state

loads at the first page loading, while the other graphic (mouse over state) loads when we pass with our mouse over our button.

This is not so practical.

But, if we use one graphic file with both states, it loads at the first page loading for both states. That’s why this is quicker and hence better.

Ok. Now lets start coding.

Insert this into your CSS file

#button a {   

display: block;   

background:  url(rollovergraphic.gif) top;   



width: 80px;   



height: 25px;   



}
#button a:hover {   

background:  url(rollovergraphic.gif) no-repeat bottom;   

}

Insert this where you want display the rollover button:

<div id="button"><a href="#"></a></div>  

6 thoughts on “Image Rollovers With CSS

  1. Hello,

    When I use display:block; it stacks and wraps my objects. I tried using display:inline; instead but it doesn’t work in IE. What am I doing wrong? Let me know if you need the code I’m using.

    thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>