Get rid of regular buttons, use link buttons

For the past 3 years I have been pushing my managers and especially the teams I work with that the web applications we make need to be visually appealing. The graphics designers I know can do amazing things. My friend Steve Sereda is an amazing graphics designer and he created some awesome skins for me for the time we worked together.

I've done a few posts leading up to this one. It all started with my post on UpdatePanel, FireFox and the Default Button, where I talked about how to get the default button working in FireFox. At this point I was in the process of moving all buttons over to fancy LinkButtons. I then wrote about CSS Pseudo Classes and their uses (which are many), and finally I finished my last post on A LinkButton, DefaultButton, UpdatePanel and FireFox, where I discuss how to get FireFox to use a LinkButton (Anchor tag) as a default button.

So let's talk about Buttons. Buttons provide functionality, and 99% of users know when they click on a button that some sort of action is going to happen. Many buttons look like this:A0

button

Now, besides the ugly border my snipping tool puts in, that button isn't that great. But should that matter? Isn't a button there to tell the user that clicking it will invoke some sort of procedure? Correct. By general standards Buttons should invoke functions, while links should be directional. However, who said a button had to be grey and ugly?

ASP.NET has the LinkButton. It gets rendered as an <a /> (anchor) tag, and because of that we can do something like this:

3 buttons

Wow, that looks way better than regular buttons. What about this:

delete

I've grown tired of using JavaScript confirm boxes. I've decided to switch to modal windows. (yes yes I know my spacing isn't right....). You can see the nice presentation, and notice the spacing... isn't that amazing?!

There's a trick to these buttons, and unfortunately you do have to put more work into them. I could make a button like this a userControl/CompositeControl, but for what I need them for, that's too much work.

Let's look at the markup I use for these buttons. This will give you more clarity when you see the CSS.

<div class="button">

A0A0 <asp:LinkButton ID="btnSave" runat="Server" CssClass="bSave" Text="Save User" OnClick="btnSave_Click"A0 ValidationGroup="userDetails"A0 UseSubmitBehavior="false" />

</div>

<div class="button">

A0A0A0 <asp:LinkButton ID="btnCancel" runat="Server" CssClass="bCancel" Text="Cancel" OnClick="btnCancel_Click" CausesValidation="False"A0A0 UseSubmitBehavior="false" />

</div>

<div class="button">

A0A0A0 <asp:LinkButton ID="btnDeleteUser" runat="Server" CssClass="bDelete" Text="Delete" UseSubmitBehavior="false" />

</div>
<div class="clear"></div>

You see that I have 3 div's, and in each div I have a LinkButton. Under the LinkButtons I have a single div with the "clear" class. My clear class does clear:both;. It clears the floats that all of these div's have.

Here's the CSS

.button

{

A0A0A0 background-color:#84A1D6;

A0A0A0 border:solid 2px #415D9B;

A0A0A0 margin:5px;

A0A0A0 min-width:70px;

A0A0A0 height:20px;

A0A0A0 float:left;

A0A0A0 padding-left:3px;

}

A0

A0

.button a

{

A0A0A0 display:block;

A0A0A0 padding:2px 5px 2px 20px;

A0A0A0 min-width:70px;

}

A0

.button:hover

{

A0A0A0 background-color: #a0bdf2;

}

A0

.button a:active

{

A0A0A0 border-top:solid 1px black;

}

A0

A0

/* Button Style */

.button a.bLogin

{

A0A0A0 background-image: url(Images/Login.png);

A0A0A0 background-position:left;

A0A0A0 background-repeat:no-repeat;A0A0A0

}

A0

.button a.bSave

{

A0A0A0 background-image: url(Images/Save.png);

A0A0A0 background-position:left;

A0A0A0 background-repeat:no-repeat;A0A0A0

}

A0

.button a.bCancel

{

A0A0A0 background-image: url(Images/Cancel.png);

A0A0A0 background-position:left;

A0A0A0 background-repeat:no-repeat;A0A0A0

}

You can notice that each .button class is floating left. I need to use Block elements for these buttons so I can apply padding, margin's etc. You cannot do that to an inline element. Seeing they're block, I want them line up, so I float them.A0 You can also see that my .button a contains the same width as the parent .button, this is because I want the entire button to be clickable, not just the link portion.

I am also using pseudo classes for this. You can see the :hover and the :active. This gives my buttons "hover" and "click" styles without having to code any javascript. (IE7 and FF).

And that is all you need to do.

Like I said, it's a tiny bit more markup and some small CSS, however, the outcome of this work is well worth it. It gives a whole new presentation to your application.

9 Comments

  • @Will Green,

    Thanks for the advice. I'll have to take a closer look at the element.

    I can see how Google would cry from that. I guess a next blog post of mine will be how to do that to the .

  • Why can't you just style the input that is rendered for a standard button or have I missed something? For example, try this (you'll have to create your own background image if you want to see that appear):

    .defaultButton {border: outset 2px #415D9B;background-color:#84A1D6;background-image:url('buttonbg.png');color:#fff;width:70px;background-repeat:no-repeat;}


  • I'll second what Will said, and add the usability perspective. For users, links are exactly what Will also describes; a non-obtrusive action, whereas buttons are supposed to perform some kind of "final" action (like "send the email", "sign me up" and so on).

    Another thing is that users know the appearance of a button when they see it, and knows what to expect from it, so to speak. Personally, having to use a fancy blue "button" with a non-standard icon to delete something makes me slightly sad :-s

    The technique, however, is nicely described!

  • The nice thing about this is that users do not under know that those are links, as they look like buttons. The final output of this I believe is a nice alternative to those that don't like the regular button look, and want to deliver a more user friendly application.

    The last project I was lead on it was required that each page have 3 save buttons:
    -Save
    -Save and Add New
    -Save and Close.

    You can believe the stress I had on how to make it look nice, buttons like these allowed me to put different icons beside the save, so users would remember which ones were which.

    I guess I'll have to perfect my technique :)

  • @Mark Smith

    I have tried that, however it renderes differently in some browsers, which is what I can't have when building a pricey application.
    As far as changing everything else, your style works great, but it won't have the full control that I was looking for.&nbsp;
    The full version of this would allow me to hover of my containing div, and the :hover would increase the height, showing 1-5 more "buttons" under it. That would effectively be like a "Combo Button".&nbsp;

  • I like linkbutton because it can be a link or a button.

    I can make the page work and the html/css person can make the decision about which it will be ;)

  • is what an gets rendered as. The main reason i didn't use that one was because of some of the styling issues.

    For internal applications this process has no flaws, except by the purists. However, after looking into having a .. approach, it seems mine isn't perfect yet :)

  • I have feel of the exact problem as you described.
    I will surely try your idea next time.
    But one thing i want's to ask is how to change the onmouse over and onmouse out image for link button.
    previously for the imagebutton i have use the attribute for that

  • the image buttons has a src. I don't believe a :hover pseudo class (CSS) will work for that. For that you might need to use JavaScript.. but I'm not sure (i'll have to play with it).

Comments have been disabled for this content.