Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  1. Code
  2. HTML & CSS

The Intricacy of Simplicity: CSS3

This post is part of a series called CSS3 Mastery.
Quick Tip: Ever Thought About Using @Font-face for Icons?
The State of CSS3 in Email Templates

Ever wondered how a particular effect was achieved in a web design, and, after zooming in several clicks, you found that the author added several subtle shadows, borders, gradients, etc? In the past, this was achieved simply by slicing out an image, and setting it as a background of some element. Luckily, with CSS3, we can be afforded much more flexibility. Now, while the code for such a simple effect might be a bit tedious, it's well worth it, and that's what we'll review in today's written and video quick tip!

Video Version

Rather watch this screencast on Screenr.com?

Text Version

It's amazing that something this simple requires that much code, but, it's not too rough, and can easily be abstracted away to a snippet for future use.

Step 1. Create the Mark-up

To make our project as cut-and-paste as possible, we're only working with an empty div. Create a new index.html file, and paste in the following:

Step 2. Create the Canvas

Next, we'll add some basic styling for the body element. This is just for the presentation, and can easily be removed. Within style tags in your header, add:

Body Styling

Step 3. Styling the Box

Now, we'll create our box, supplying a width and height.


Step 4. Rounded Corners

We should all know about CSS rounded corners by now. Let's go ahead and implement that.

Rounded corners

Note that we're also supplying the final spec, of "border-radius," in addition to Mozilla and Webkit's versions.

Step 5. Border Colors

Mozilla offers a handy property, called "-moz-border-*-colors." This allows us to set an infinite number of colors for a border. To achieve a subtle "double-border" effect, let's implement this property.

Note how the number of colors we supply are the same as the border width that we set at the beginning (2px). Also, don't place commas after each hex value; I made that mistake at first!

Border Colors

Step 6. Compensating for Webkit

To the best of my knowledge, webkit doesn't currently support border-colors, though it's possible that I'm wrong. If I am, please leave a comment and let me know! Anyhow, to mimic this effect as best as we can in Safari and Chrome, we'll use box-shadow.

Note that the provided values refer to the X offset, Y offset, blur, and shadow color, respectively. By passing -1px as the Y offset, we can push the shadow upwards.

In Safari

Step 7. CSS Background Gradients

The final step is to supply a subtle background gradient for our box. However, we must be sure to provide a fallback solid color for the browsers that don't support CSS gradients.

Unfortunately, Mozilla and Webkit don't quite agree on the syntax for gradients, which makes the process extra irritating. If it's too confusing, you can use a new service called CSS3 Please to auto generate each browser's syntax; it's very cool!

Final Product

You're Done!

It's amazing; looking over our final image, it's hard to tell what we actually did! But this is a good thing; subtlety is key in all aspects of design. Thanks for reading/viewing!

Final Code

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