Skip to main content

CSS Rollover Buttons

My work place tasked me with trying to be as purist as possible with HTML and CSS for an interface their web application. Without any formal web development background, I have always been one of those who intermingle the code and have presentation within the HTML.

I think it came out pretty well. I separated design from content in addition to separating the dynamics. Mind you, I even separated out all the server talk and taught myself some XML/XSL in the process. After all that I learnt Ajax, without realising it.

One little nugget from all this is creating a pure CSS rollover button for the menu, without Javascript. There's alot of websites that help out in this, but they are not "pure" as they involve you including the image in the HTML and to perform some shifting with the image. Hell no to that.

My way leaves out the usual ul tag and dives straight into the anchor (a) tag as it should be:

a href="links.htm" id="linksButton" title="Links">

Embedded within the anchor is a blank image, which can be a 1-pixel transparent GIF. The image size but be set due to browsers behaving differently.

img src="assets/buttons/blank.gif" weight="45" height="45" title="Links" />

That's fine enough, but the magic is the assigned id for each anchor which must, obviously, be unique. The id is used within the CSS. First for the initial UP state:

#linksButton img {
background-image:url('./buttons/linksBtn_up.gif');
background-repeat:no-repeat;
width:45px;
height:45px;
}

Here I set the desired image icon as the background image and ensuring that it does not repeat, for safety measures. Due to browser quirks you need to set the size of the image tag here as well.

The rollover is set using the same id:
#linksButton:hover img {
background-image:url('./buttons/linkBtn_down.gif');
}


And that's it. You will have a pure CSS rollover, without any manky HTML and Javascript. This is also accessible in case you want to fulfill the WAI Triple-A Compliant guidelines by the W3C.

Beacuse it's easy, I am now a fan of puritan coding of HTML and CSS. Spread the love.

Comments

Popular posts from this blog

Open Source alternatives to Adobe Creative Suite

With the take over of Macromedia by Adobe, they have increased their arsenal of design packages, as well as the price. No-one can do pretty much without the popular package of Photoshop for their images, and Dreamweaver for websites, especially aspiring design students who do not have much money. Nevertheless, open source software has come to save the day. What is open source software? In a nutshell it is free software with its source-code freely available to those who would like to expand or improve on the software. To expand further, anyone who’s tinkered with the source code such as optimisation or additional functionality can resubmit it back to the holders and let others enjoy the fruits of your labour. I have trawled through the World Wide Web to find out how everyone can benefit from Open Source to build up their own studio and compete against Adobe Creative Suite. All this for free, apart from the cost of the Internet. I am planning to have a facility where you can purchase...

Download free software and help the poor

Yes, you heard me. To celebrate this festive season, SoftMaker has made their excellent alternative to Microsoft Office freely available. On top of this they will donate to charity with every download. With such a commendable act, why not contribute towards a good cause and try out an Office alternative. So head over to Load and Help ( http://www.loadandhelp.de/home-en.html ).

21 Years of the Web

Who would have thought that an independent contractor in the 1980s would have created the foundations of a revolutionary technology, which changes the way we live? It all began in the European Organisation for Nuclear Research (CERN), in Switzerland, when Tim Berners-Lee proposed and built a database of people and software models that can be shared over the Internet using the HyperText. By the end of 1990s, he created the set of elements that build a web page and its access, HTTP and HTML. In fact he also created the first browser - WorldWideWeb. The rest, you can say, is history... with a large commercial undertaking and the growth of servers across academia then the world Now, there exists well over 80 million websites and a growing user base - hundreds of millions. So it's happy 21st birthday to the Web. Celebrate good times.