The Blog

Rounded form buttons

To be precise, the submit buttons: input type="submit". Very often designers want to somehow emphasize these buttons and are not very pleased with an answer “well, how about bold and colored caption?” :)

Recently, at the office, I had client request to create a design like this:

The HTML I had already was like this:

HTML:
  1. <div class="buttons"><strong>
  2.  
  3. <input type="submit" value="Continue →" /></strong>
  4. <span class="lesserbtn">
  5.  
  6. <input type="submit" value="Cancel" /></span></div>

There was no chance to change this into anything drastically different as bunch of server-side code depended on form submit buttons being input elements. Thus, I went with this code and looked for CSS solutions.

One really helpful fact was that all captions were one line of code. Thus, I was able to use one long image with rounded corners. I had two nested elements as well, which is enough to get the design up.

Basic idea I had was to put background image on both the input and its parent element, both aligned to opposite corners.

Step 1 — remove default styles

This is fairly easy, but necessary.

CSS:
  1. .buttons {
  2. line-height: 1;
  3. }
  4.  
  5. .buttons input {
  6. line-height: 1;
  7. font-size: 1em;
  8. font-weight: bold;
  9. margin: 0;
  10. padding: 0;
  11. border: 0;
  12. }

Step 2 — enclosing element

Now, let’s start with the styles for the button first.

CSS:
  1. .buttons strong, span.btn {
  2. background: url(btn-round.png) no-repeat left;
  3. padding: 1em 0 1em 5px;
  4. margin-right: 10px;
  5. cursor: pointer;
  6. }

This is left side of the button. Note the use of vertical paddings. Since this is inline element, they do nothing to the text but they do expand inline box. That way, background graphic is fully revealed.

Step 3 — actual button

CSS:
  1. .buttons strong input, span.btn input {
  2. color: #000;
  3. background: url(btn-round.png) no-repeat right;
  4. margin: 0 -5px 0 0;
  5. padding: 1em 10px 1em 5px;
  6. border: 0;
  7. cursor: pointer;
  8. }

Same thing for internal element, but this one is forced 5px to the right to reveal the rounder corners of the previous element.

And that’s it. Fairly simple and mostly works ok. Here’s an example page.

Problems

It’s strange that it does not work ok with all fonts. Example page shows that when Calibri is used, images don’t always line up. In Safari, they don’t fully line up even for Helvetica Neue. They do line up for Verdana, Georgia, Arial. In Opera 9.5 Calibri example is the worst.
Second problem is that in some cases, when larger font sizes are used, images again don’t line up.
Amazingly, the only browser I didn’t have an issue with is IE, both 6 and 7.

I could not get to the bottom of this. If anyone have any ideas, please share. Inline box is a very complicated issue and I’m sure there’s something I’m missing.

Banca

Banca

Beautiful and functional currency converter, supports just about any currency in the world.

Go Couch to 5k

Go Couch to 5k

The most popular starter running program in beautiful feature-rich app (GPS tracking, charts, detailed history etc)

Quickie to do

Quickie to do

The fastest short-term task-list / check-list app on the App Store. Really.

Guerrilla Cardio

Guerrilla Cardio

The most challenging high-impulse interval training in the world.

Run Mate

Run Mate

A versatile running coach app, with unlimited number of running programs. Perfect for casual runners.

12 Comments

Feel free to chime in, looking forward to it. Leave a Comment

  1. Priit Pirita says:

    try this:

    .buttons strong, span.btn {
    background: url(btn-round.png) no-repeat left;
    padding: 1em 0 1em 5px;
    margin-right: 10px;
    cursor: pointer;
    display: block;
    width: 15px;
    }

    /* now actual buttons */

    .buttons strong input, span.btn input {
    color: #000;
    background: url(btn-round.png) no-repeat right;
    margin: 05px 0 0;
    padding: 1em 10px 1em 5px;
    border: 0;
    cursor: pointer;
    display: block;
    }

  2. Aleksandar says:

    display:block and short width does help with alignment, but unfortunately forces remaining part of the text into second line (like that Cancel button I have on the example page).

    The perfect solution here would be inline-block, which is not widely supported yet.

  3. Priit Pirita says:

    Yeah, should have figured that out earlier. The devil here’s is the inline blocks, where text alignement depends from fonts baseline. Baseline is slightly different in diffrent fonts ( I mean how many % below and how many % above the baseline). So the solution is to give input element same font family as outer div’s. Currently you have default font there.

  4. Aleksandar says:

    Heh, interesting.

    I tried to place font-family:inherit on lower (problem) example and that resolved the issue. However, it then created inverted problems at the top — now it’s misaligned on the top edge. :)

    Some creepy stuff happening here…

  5. sam says:

    regarding Calibri font; is that a web supported font anyway? If not, no wonder why it doesn’t work on regular browser. The same goes with Helvetica Neue (though i love it).

  6. Aleksandar says:

    Calibri is one of the 5 C fonts that Microsoft introduced with Vista. They are great fonts, and all look great on screen.

  7. Daniel says:

    Passing through. The problem is your line-height not being applied to your inline elements. This is the same issue as when you float a span to the right in a navigation and are noticing the right span being kicked-up higher than the rest of the navigation.

    Set your line-height for every element you wish to use, and that might solve the problem.

    Hope that helps.

Trackbacks for this post

  1. 15 Tips and Techniques for Styling the button element : Speckyboy Design Magazine
  2. 45 Powerful CSS/JavaScript-Techniques - Smashing Magazine
  3. 15 Tips and Techniques for Styling the Button Element « Extreme Design Studio Blog v4.0
  4. 35+ Essential Submit Button Enhancements | tripwire magazine
  5. 45 Powerful CSS/JavaScript-Techniques « DownGraf – Design weblog for designers

Leave a Comment

Add your comment here, just please be civilized and stay on topic.