Unlimited WordPress themes, plugins, graphics & courses! Unlimited asset downloads! From $16.50/m
  1. Web Design
  2. Site Elements

Orman Clark's Chunky 3D Web Buttons: The CSS3 Version

Read Time:8 minsLanguages:
This post is part of a series called Bringing Premium Pixels to Life.
Orman Clark's Vertical Navigation Menu: The CSS3 Version

Today we'll be making some awesome CSS3 buttons! They're based on the popular PSD freebie Orman Clark made for his website Premium Pixels. We'll try to make a CSS copy of them, as precisely and with as little HTML markup as possible.

Editor's Note: Orman has sportingly allowed us to CSS-ify any of his Premium Pixel freebies that we choose. These chunky buttons are just one of the many freebies available, so expect more tutorials like this in the future. Huzzah!

Step 1: Outlining the HTML Document

We'll start off by creating a new HTML document. I based mine on the HTML5 boilerplate, just to be able to start quickly and with the perfect document markup. I used the css normalization document that comes with it, too. Then we'll add a list with some basic anchors in it. Simple as that, we don't need any extra spans or divs, our good friend CSS3 will take care of that.

To be able to give it some css styles, we give the list a class 'buttons'. And since we're going to show all the colors Orman used in his design, we'll give each link a different color as a class.

That's all we need for now, our HTML document is done!
Here's what it should look like when you view it in your browser so far:

Simple HTML Markup

Step 2: Some Basic CSS Styling

Before we start with styles like gradients, rounded corners etc., we'll apply some basic styling first.
Nothing special here, just the usual CSS2 stuff.

We can easily alter the colors of the buttons too, since we added classes. So we'll do that for every other color, for example gray. You can check all the color codes in the demo file.

If you did everything well, you should have something like this. Which is nice.. if we were living in 2008!

Looking good. Bit boring though!Looking good. Bit boring though!Looking good. Bit boring though!

Step 3: Double Borders all the Way!

Now, if you take a little closer look at the photoshop file, you'll notice that there isn't only a thicker border on the bottom, but also a thinner one all the way round, and a little extra line between the thick part and the actual border. To translate that last detail to css, we'll be using a CSS2 trick, the :before and :after pseudo-elements.

We'll position these elements - which we can see as separate boxes - exactly behind our actual button with the position property. To save some css lines, we'll style both elements first and then add the values for the before-element only.

Things start looking good when we're adding the right colors!

Added some detailsAdded some detailsAdded some details

Step 4: Adding CSS3 Magic

Now what you guys have all been waiting for, the CSS3 part. We'll start by adding rounded corners to all our buttons:

And then of course our :before and :after elements need rounded corners too, to make the borders fit. However, the :before element doesn't need the top corners to be rounded, otherwise we'll see a little bug. Since the :before element is the one with the lowest position, we'll add the box shadow to this element instead of to the main one.

Lastly we'll apply some gradient backgrounds, an inner shadow and some text shadow for every separate color. We'll add the :visited state too to prevent bugs in IE6.

This should be our result. Lookin' good, eh?

Our final result!Our final result!Our final result!

Step 5: Didn't We Forget Something?

There's one important thing we still need to do; Orman made a design for the active state too. So of course we will add that to our css version!

We'll put the code for the active state under all our color definitions since some of these values need to be overwritten. The first difference with the other states is that it has no borders. It's also positioned a bit lower to suggest indentation. And we'll need to use 2 shadows instead of one: a normal, white one and a second, inner one that is transparent. Lastly, we don't need the :before and :after pseudo-elements anymore.

This is what our buttons should look like in active state:

Active buttons = happy buttonsActive buttons = happy buttonsActive buttons = happy buttons

Step 6: (optional) Older Browsers

Now we have some nice CSS3 buttons that work in all modern browsers. But what about Internet Explorer, for example? IE8 and lower don't support box or text shadow, nor gradients.

To be able to style our elements specifically for these browsers, we could use Modernizr, a javascript library that detects whether your browser can handle CSS3 and HTML5 properties. It does not fix older browsers' issues, it adds classes to the html tag (reporting whichever capabilities are and aren't available) to allow alternative styling.

Another option would be making these browsers behave with some other javascript libraries (those are called polyfills), but that's something we're not going to cover in this tutorial. Instead we're just going to use an image for older browsers.

First we'll make our custom build version of Modernizr, that way we don't have to carry all the superfluous javascript with us. We can do that easily on their website. When we implemented the javascript in our html file, we just need to define the alternative styling for specific html classes. We're going to use an image for browsers that don't support (one of) the 2 most notable CSS3 effects we used, border radius and css gradients. And since some older browsers don't even support generated content (:before and :after), we'll mention that one too.

To improve performance, we use a CSS Sprite for the hover and active state. And the :visited state is still included to prevent the IE6 bug.


So, now we have our fully cross-browser CSS3 buttons! You'll probably think that this looks like a lot of code for 10 buttons, but of course this is only a demonstration of what you can or can't do with CSS3. You're free to do whatever you want with it!

So far my very first tutorial.. I hope you liked it, thanks for reading!

Did you find this post useful?
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.