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.
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">
<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.