1. Code
  2. HTML & CSS

5 Techniques to Acquaint You With CSS 3

Read Time:6 minsLanguages:

CSS is a well-known, widely used language to style websites. With version three in the works, many time-saving features will be implemented. Although only the most modern browsers currently support these effects, it's still fun to see what's around the corner! In this tutorial I'll show you five techniques.

1: The Basic Markup

Rounded Corners ImageRounded Corners ImageRounded Corners Image

Before we start with this tutorial, let's create the basic markup that we will be working with throughout the tutorial.

For our xHTML, we'll need the following div elements:

  • #round, to apply rounded corner CSS3 code on.
  • #indie, to apply an individually rounded corner on.
  • #opacity, to show the new ways CSS3 handles with opacity.
  • #shadow, to show you how to create drop shadows, without Photoshop.
  • #resize, to show you a new sort of CSS, to resize elements.

For this, our xHTML will be:

In our HTML document, we've created some div elements, with the IDs stated above.
Let's quickly create a base CSS file.

As you can see, we've given all div tags a width and height of 300px each. We also forced them to float to the left, leaving us with a page full of divs to play with.

2: Rounded Corners

Rounded Corners ImageRounded Corners ImageRounded Corners Image

It can be a hassle to create rounded corners. First, you must create the images. Next, you have to create more elements to have the rounded corners set as backgrounds. You know the drill.

This problem can be easily solved with CSS3, with the property called “border-radius”.
We'll first create a black div element and give it a black border.
The border is there because we need to "execute" the border-radius property.

We do this like so:

Once you've created the div, refresh the page. You should now see a black, square div with a width and height of approximately 300px. Now, let's work on the rounded corners. This can be accomplished with only two lines of code.

As you can see, we've added two nearly identical lines, with the only difference being "-moz" and "-webkit". -moz refers to Mozilla Firefox, and Safari/Google Chrome use the -webkit prefix.

Refresh your HTML document and you'll see a rounded div - nice and smooth. Well, smooth... In Firefox and Safari, yes, but Chrome renders a slightly pixelated edge.

Back to our code, "border-radius" needs a value. This value determines the sharpness of the corner; the bigger the value, the rounder the corner - just as in Photoshop. To the best of my knowledge, there's no maximum value for this element.

3: Individually Rounded Corners

Rounded Corners ImageRounded Corners ImageRounded Corners Image

Creating traditional rounded corners can drain your day. Luckily, CSS3 solves it!

This property is quite similar to our previous one. It also uses "border-radius", however we'll slightly modify our code.

We do it like this:

We've added "topright" and "bottomright" to our code; this refers to the top and bottom right corner of the div element. With these new properties, you can easily implement a "tab-like" feature.

The additions to be used are "topright", "bottomright", "bottomleft" and "topleft".

4: Changing Opacity, The CSS3 Way

Rounded Corners ImageRounded Corners ImageRounded Corners Image

Currently, you need to write several lines of CSS to adjust the opacity of elements (hacks). Once again, CSS 3 simplifies the process.

This line is easy to remember as well, it's just "opacity: value;". Easy right?
Our code will be:

5: Drop Shadow!

Rounded Corners ImageRounded Corners ImageRounded Corners Image

In Photoshop, it's a trivial task to create drop shadows. However when implementing them into your web applications, you'd probably save the shadow as an image, and then use it as a background. No More! (At least for the modern browsers.) Unfortunately, only Safari and Chrome support the feature at this time.

The code requires just one line, but it's quite long and has 4 different values!

For the first value, I've used 3px. This one determines the horizontal distance between the drop shadow and the div element. Moving along, the second value, 5px, determines the vertical distance between the shadow and the box.

Yet there is another px value, 10px. This is the radius of the shadow - which in plain English means the blur of the shadow, or how "wide" the gradient is.

Finally, the last value determines the color of the shadow. This means the shadow is not only limited to grayscale; we can also use red (#f00) as a value, which renders a bright, red shadow.

For our final code, it comes down to the following:

As you can see I've given the div a white background, a black border and a light grey shadow.

6: Resize It!

Rounded Corners ImageRounded Corners ImageRounded Corners Image

With the most recent version of CSS, it's possible to resize elements. (It currently only works in Safari.)

With this code, it's possible to make a tiny triangle appear in the bottom right corner of an element. You may then drag it to resize. The code to follow is yet again very easy, and just requires one line and is supported by some older elements you might already know. These are "max-width", "max-height", "min-width" and "min-height".

The code is as follows:

In the code I've used 2 additional lines to our normal CSS, "resize: both;" and "overflow: auto;". The line with overflow is needed to make the resize work, it can be any sort of "overflow" value, as long as it's there.

The other line I've used is "resize: both;". This line specifies that the element can be resized in both horizontal and vertical directions.


Rounded Corners ImageRounded Corners ImageRounded Corners Image

What should you take from this article? In the next few years, your job will become easier, webpages will load faster, and you'll be left with more time for your family! Though you can't rely on these effects to work in all browsers just yet - there's absolutely nothing wrong with applying a rounded corner to a div in one browser, and not the other. Consider it an upgrade!

For more information on CSS3, you can visit

  • Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.

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