Home arrow Style Sheets arrow Page 4 - Building Rounded Corners with CSS3
STYLE SHEETS

Building Rounded Corners with CSS3


In this first part of a series, I provide you with a friendly introduction to building rounded corners with CSS3. In this initial stage, I show you how to create this popular decorative effect on web pages using four different background images, which were assigned to the same HTML container. This technique is impossible with current CSS methods.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 3
March 10, 2010
TABLE OF CONTENTS:
  1. · Building Rounded Corners with CSS3
  2. · Building rounded corners the old way
  3. · Creating rounded corners using fewer divs
  4. · Building rounded corners using the CSS3 specification

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building Rounded Corners with CSS3 - Building rounded corners using the CSS3 specification
(Page 4 of 4 )

As I said at the beginning of this tutorial, CSS3 has several properties that make building rounded corners a clean and straightforward process. In consonance with the examples created so far, the first approach that I plan to cover here will implement the effect via multiple background images assigned to a single HTML container. Indeed, this sounds like a beautiful utopia, but hopefully it will come true in a near future, as browsers continue adding support for CSS3.

For the moment, however, take a look at the following example, which renders a rounded corner container using the same four background images that you saw in a previous segment:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Rounded corners using four different background images within the same element</title>

<style type="text/css">

body {

    padding: 0;

    margin: 0;

    background: #fff;

    font: 1em Arial, Helvetica, sans-serif;

    color: #000;

}

#wrapper {

    width: 960px;

    margin: 0 auto;

}

#header, #content, #footer {

    padding: 30px;

}

/* uses four different background images in the same element */

.rounded_container {

    width: 400px;

    padding: 10px;

    background-color: #39f;

    background-image: url("tl.gif"), url("tr.gif"), url("bl.gif"), url("br.gif");

    background-position: top left, top right, bottom left, bottom right;

    background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;

}

</style>

</head>

<body>

<div id="wrapper">

    <div id="header">

        <h1>Rounded corners using four different background images within the same element</h1>

    </div>

    <div id="content">

        <h2>Main content section</h2>

        <!-- rounded container -->

        <div class="rounded_container">

            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

        </div>

    </div>

    <div id="footer">

        <h2>Footer section</h2>

        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

    </div>

</div>

</body>

</html>

Did I tell you before that building rounded corners with CSS3 was a breeze? Well, the above web page demonstrates this fact pretty clearly. As you can see, in this case the effect has been created by attaching four different background graphics (one per rounded corner) to the same div, a process known in CSS3 jargon as “layering background images.” At the time of writing, CSS3 will let you layer up to eight background images inside an HTML element, but be sure to keep an eye on this, as the specification is subject to change without notice.

Unfortunately, most browsers, including Internet Explorer 7/8, Mozilla Firefox and Safari, don’t currently support layering multiple background images, but hopefully they will change in the near future. That’s why I haven’t provided you with a screen capture that shows how this technique is rendered by a specific browser; however, the final result should be quite similar to the example shown at the beginning of this tutorial.

Final thoughts

In this first part of the series, I provided you with a friendly introduction to building rounded corners with CSS3. At this initial stage, I showed you how to create this popular decorative effect on web pages using four different background images, which were assigned to the same HTML container, which is impossible with current CSS methods.

Even though this approach is already much easier to implement than using multiple containers or even JavaScript, the truth is that CSS3 offers an even more direct way to create rounded corners. It involves using its handy “border-radius” property. This is exactly the topic that I plan to discuss in the upcoming part of the series, so I suggest that you make sure to come back for it!


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials