Scott Boms

Our May 2006 Back Catalogue

Sliding Doors of CSS Buttons

One of the small tasks I set for myself in working on an upcoming web application project was to construct any buttons required in the app using simple anchors rather than using either input or button elements, handling the visual appearance with CSS.

This was a challenging task in some respects due to some cross-browser quirks (what else is new?) and the simple desire to not create excessive code for the sake of nice buttons.

In the end, a smattering of ALA technique and home-brewed trial and error did the trick and allowed a fairly robust and flexible system for constructing buttons while aiding accessibility and ideally making users with screenreaders happy as well.

The main designer/developer benefit is that these buttons are easy to style, can be easily repurposed to allow different styling and allow for translation into other languages without having to produce countless images. They also happen to work based on my testing in IE6/Win, Safari and Firefox. I haven’t done any testing in Opera, but I suspect that they should be fine in newer versions of that browser as well.

Cutting Up Your Buttons

Since this technique is based on Doug Bowman’s Sliding Doors technique , I suggest you give it a brush-up read if necessary. It lays the overall foundation for the sliding door buttons technique.

CSS Sliding Buttons
An example of Sliding door buttons with CSS

The short version is this: we need two images. A left side and a right side. The left side will occupy the space from the left edge of the button text to the left edge of the button background itself. You should get the general idea from the screenshot above.

One key thing to remember is to make the background of the button on the right side wider than you need. The reason for this is to allow the button to expand and contract with the length of the button text and to allow a certain amount of font scaling.

Mark Me Up

The basic markup is as simple as it gets. You need an anchor and a span. It looks a little something like the sample below.

<a href="#" title="My Button"><span>My Button</span></a>

Simple, no? To style the button, you apply the left background image to the anchor and the right background to the span, remove the text-decoration from the links, add some padding to allow the entire button shape to be visible and set the span to display-inline.

The reason for placing the span inside the anchor is simple: doing it the other way around works fine until you get into IE and it all falls apart. Placing the span inside brings the added benefit of ensuring the entire button shape will be clickable by the user.

Code Sample

You can grab a quick sample of the sliding buttons technique in use here.

It Was 365 Days Ago…

It was 365 days ago that I officially launched Wishingline Design Studio, Inc. as a true business entity and on from just being a side-project. The last year has brought great change, new challenges and new opportunities, nearly all of which were a bit expected but very welcome!

I’ve had the opportunity to work with some great clients, such as FiveRuns, HSBC Private Bank, St. Joseph Media, BeamEcho, Group Kae, Sahara Dance, Big Image, Cocoa Stuff, Masterfile, Digital Cement, IndexCore (IC), Floral Fetish Design, Michael McLuhan and more.

It’s thanks to them that I can say the last year has been a tremendous success and has left me looking towards and even better 2006!

Cheers!

« April 2006June 2006 »