Rollover CSS Image Menu  

There are now loads of places on the Internet where one can access free CSS menu's. But of the many that are available very few suceed in replicating the prehistoric roll-over image menu using javascript image replacement techniques, with only lovely CSS. I have managed to create one that works in both decent web browsers and crap ones (Internet Explorer),

First I needed to remove all padding and margins from the page:

* { padding: 0em; margin: 0em; }

Then the CSS for the #nav container div:

#nav img { border: none; }
#nav li { display: inline; list-style:none; }
#nav li a { float: left; display:block; width: 37px; height: 50px; margin: 5%; }
#nav li a img { border:none; vertical-align:bottom; /* for IE6 */}
#nav li a:hover { visibility:visible; /* for IE6 */ }
#nav li a:hover img { visibility:visible; /* for IE6 */ }
#nav li a:hover img/**/ { visibility:hidden; /* hide from IE5.0/win */}

Internet Explorer requires something to happen on a:hover as well as a:hover img.

The menu list items all use different images on rollover so I defined each with a different ID on the anchor element:

#one { background:url( http://www.alanwho.com/examples/css/rollover_menu/1over.png ) no-repeat left bottom; }
#two { background:url( http://www.alanwho.com/examples/css/rollover_menu/2over.png ) no-repeat left bottom; }
#three { background:url( http://www.alanwho.com/examples/css/rollover_menu/3over.png ) no-repeat left bottom; }
#four { background:url( http://www.alanwho.com/examples/css/rollover_menu/4over.png ) no-repeat left bottom; }

Lastly I created a div with an id of nav and applied the CSS into the final XHTML:

The Final Rollover CSS Image Menu XHTML .

Recent article: CSS Articles
CSS Content? Using tables within the content of your page is a major no-no, the whole intent and purpose of CSS is to control the style of your page elements, this is done using an external stylesheet.

An external Stylesheet? External stylesheets give you the control of your whole website from one single file rather than trying to edit your whole websites CSS using global search and replace or by opening each page individually.

If you are new to this HTML malarkey then welcome, you have just embarked upon a new learning curve that does not take too long to master. Before the invention of CSS everything within a webpage used to be designed using tables.

Indeed there are still a lot of html editors out there that still use tables to format a pages content, one strong word of advice, get rid of that software and start again. Tables are not extinct within webpages but they should only be used for the purpose of presenting data.

Beginning CSS? I am not going to use this article to give you a whole list of tags and how to apply them, that information would be too easily ignored. There are thousands of well rounded websites available on the net today that can walk you through the first stages of CSS, the one I would recommend would be: W3Schools CSS intro this is a perfect place to start learning CSS, in the interests of parity and fairness I will also recommend What can be achieved using CSS .