administration mode
Pssst...Ferdy is the creator of JungleDragon, an awesome wildlife community. Visit JungleDragon

 

Creating a slick button bar »

FERDY CHRISTANT - JAN 15, 2010 (11:25:37 AM)

In this post I will explain the JungleDragon button bar, which is a button bar that applies to an image. I will detail how it works, why it was designed that way and how it was made. Perhaps there is something you can reuse.

How it works

This is  what the button bar looks like below an image:

The button bar is a context menu of actions one can apply to the image above it. Each button has a number of states. For one, there is the invisible state. Perhaps silly to mention, but the button bar will only show a button when it is relevant. This can be based on the authorization of the user, but also the state of the image.

Next, there is the hover state, where a user hovers over a particular button:

There is also a disabled state, for example when a user has already applied the action. An extra explanation is given using a tooltip:

Finally, there is the active state. It looks similar to the hover state but the interaction is different. In this example, the user has clicked the image to toggle zoom mode. Although the zoom button was not clicked, it was activated indirectly:

Design considerations

There are many ways to design a button bar like this, so hereby I will explain my reasoning behind it. We web developers tend to default on standard icon sets such as Silk for our icons. As nicely as those icons look, I still decided to chose a different path, here's why:

  • I believe that content matters most, and that content should stand out, not icons. Perhaps this is a personal preference but I dislike how bright colorful icons curse with an otherwise consistent user interface style. especially when most of your audience will simply view content and not apply any action on it.
  • Look at real world icons, such as traffic signs, airport signs and such and you will see that most of them are monochrome, using two colors with a high contrast for optimal legibility. 
  • Icons are ambiguous. A star icon could mean "rate this" or "add to favourites". What is the agreed icon for a "history"? To be sure that the user understands the icon, it makes sense to supplement it with text.
  • Standard icons sets typically do not have different states (normal, hover, disabled, active).

All in all I believe I had good reasons to go the custom path, so let's see how it was done.

How it's made

It's simple to create a button bar like this, but there's some interesting clues to share nevertheless...

For one, I did not create the icon illustrations myself. I grabbed them from the jQuery UI theme page. For each icon that I needed, I cut out just the icon (not the box around it) and paste it into my button box template in Photoshop. If that page did not provide the icon I needed, I would use an icon search engine for my needs.

Next, the text. It would be ideal if we could make the icon button text part of the HTML. At the same time, we do not want it to take up too much space. Unfortunately, browsers suck at rendering fonts at such a small size. Therefore, the texts are part of the icon images. In order to make the texts look as clear and crisp as they do at such a small font size, we need to use a pixel font. I used PF Arma Five for it. It is important to realize that pixel fonts are designed for one size only, in this case 8px. Therefore, do not apply any effects on it in Photoshop and do not change the font size.

Finally, integrating the result into the web front-end. The default way would be to simply cut out the images and refer to them in our web pages. However, given the number of buttons and their states, this could easily lead to a dozen or more HTTP requests. An additional problem is that when we do not preload all states, the user may have to wait for an image to be loaded when they hover a button. 

This is easily avoided by using a spriting technique. Instead of loading dozens of icon images, I only load one:

Next, I use CSS background image positioning to show the correct part of the icon. The result is a single HTTP request for the entire button bar and no load times for the hover states. If you are new to this technique, I can recommend this introduction.

Main buttons

Whilst on the subject of buttons, I want to share the improved look of the action buttons I use in forms:

It is created using this technique. I love the result. What's also nice is that the color is controlled in CSS. The shadows and shine effect are an overlay. It also looks the same in Internet Explorer, which is notoriously bad in button rendering. However, there are downsides to this technique:

  • The markup is not pure. It uses a href links instead of input or button HTML elements. Unfortunately, there is no other way to make a button look this nice in IE.
  • One consequence of not using a normal submit button is that submit behavior that you rely on will stop working. For one, you will have to use Javascript to submit the form upon clicking the link. If Javascript is disabled, you're out of luck.
  • Another consequence is that hitting ENTER to submit a form will not work. A cheap trick to work around this is to include a input button or image of type submit, and make it invisible through styling.

I'm still in doubt about this one. It feels dirty, even though JungleDragon needs Javascript to work anyway. Still, the result is beautiful. Once again it is Internet Explorer who makes the web miserable.

So, what do you think about my approach towards buttons? Do my design considerations make sense?

Share |

Comments: 5

COMMENT: JERRY CARTER email

JAN 15, 2010 - 01:55:01 PM

comment » The use of sprite is a great way to go. It's a technique that goes way back to early game programming and I've used it myself a couple of times. Very efficient.

On the subject of states, I've had the same experience as you trying to find universally applicable icons and, like you, have also wound up rolling my own quite often. Paint.NET is a great free alternative to PhotoShop, for anyone bemoaning the cost. You can make great looking alpha shaded sprite sheets in any image format needed.

With the overlay button - I think you probably need the alpha shader active x control hacked into it for IE alpha rendering - no?

I think most platforms that will be likely to have JavaScript disabled or unavailable are going to be pretty terse rendering devices anyway - so a loss of glossy colorfulness is sort of expected in those environments. Graceful failure mode with noscript tag is possible. «

COMMENT: CHRIS TOOHEY emailhomepage

JAN 15, 2010 - 02:07:57 PM

comment » Sprites rule!

Excellent article, and something that I think any application developer - regardless of platform or client-type - should check out. «

COMMENT: FERDY

JAN 15, 2010 - 14:34:52

comment » @Jerry, good to hear you have similar experiences.

No, the alpha shader is not needed. The overlay is a PNG which has the partial transparency. This works fine in IE7+, for IE6 there is a hack.

About Javascript, the problem is not in rendering actually. I renders the same with or without javascript, it is the behavior that is different. Without javascript enabled, clicking the button will not submit the form.

@Chris,

Thanks, fully agree that sprites are not utilized enough. I still see implementations where for example TinyMCE makes 50 or more HTTP requests just to load an editor. Sprites are not for everything, but definitely for situations like this. «

COMMENT: BAS PETERS

JAN 15, 2010 - 02:37:58 PM

comment » The contextual buttons are nice. I use the jqueryUI icons too, they are unobtrusive and look quite nice with different layout styles.

The form buttons however I do not like. First of all, there should not be three images, the sliding doors technique uses just 2 images. The overhead of 1 extra http request is bigger than the slightly larger second image.

Secondly, and this is my biggest pain, the nice anti-aliased round corner is anti-aliased against a white background. Transparency is not possible here because of the background color and the buttons will look really ugly on backgrounds other than white. Just try a bright red background and you will immediately know what I mean. You would have to refrain from using the buttons on any other background than white, or make different versions of the glossy PNG for each background color.

The proper solution is sadly not supported in IE (CSS3 rounded corners). To make all buttons in Photoshop whenever you need a new color is also not desirable. Nowadays I sometimes choose to not have rounded corners in IE, while supporting all other browsers using the CSS3 style. Square borders do not look as nice, but with glossy interior and some CSS magic, it still looks acceptable.

There is a solution that will work in ALL browsers and it does not involve creating buttons in Photoshop for every hue that is needed. Sadly this solution is kind of verbose and not easy to set up. It involves generating the necessary background images for the buttons in GD automatically, based on the color and size input. For example, one could make use of a mod_rewrite statement that rewrites a url like button_left_ff0000_cornerradius_16.png into button_image.php?color=ff0000&radius=16. The generated image can be cached on the filesystem and resent if it already exists. By using a mod_rewrite url the browser sees a valid image url and is able to apply proper local caching as well.

Drawing anti-aliased arches in GD is not possible natively, but ofcourse there are kind people that already experimented with this. A nice example can be found here:

http://mierendo.com/software/rounded_css_boxes/

Lastly something regarding your comment on the markup of the buttons in html. This should work from IE5 upwards to style submit buttons:

Keep up the good work on JungleDragon 18 «

COMMENT: FERDY

JAN 15, 2010 - 14:54:19

comment » hi Bas, how's life? Thanks for the excellent remarks, my response:

- Agreed on the 3 images being too much for a button. I am considering using spriting for that too to cut it back to just one.

- You are right about the anti aliasing issue, I actually tried to use the button on a bright red background and it looks crap. Personally, I can live with this issue by having multiple overlay images, a set per theme.

- I have considered using GD (I use it for other purposes as well) but I find that solution to be a bit of overkill for just styling a button.

- Finally, about rounded corners using border-radius, I'm a heavy user of that. JungleDragon has a LOT of rounded elements, which will look square in IE. Still, for buttons I cannot get it to look as nicely as the method I currently use. Both Firefox (crappy font-rendering) and IE (state transitions and padding problems, lack of rounded corners) have their own rendering issues when it comes to fonts.

All in all, given the cirumstances I have chosen style and consistency over semantic purity and maintainability. I may revisit this decision some day 18 «

RATE THIS CONTENT (OPTIONAL)
Was this document useful to you?
 
rating Awesome
rating Good
rating Average
rating Poor
rating Useless
CREATE A NEW COMMENT
required field
required field HTML is not allowed. Hyperlinks will automatically be converted.