Home arrow JavaScript arrow Page 2 - Building Rounded Corners With CSS and JavaScript
JAVASCRIPT

Building Rounded Corners With CSS and JavaScript


Rounded corners give your website a professional, polished look. Unfortunately, the old school way of building rounded corners is rather messy and involves a lot of redundant markup. This article explains a much cleaner way of achieving the same effect.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 58
January 03, 2005
TABLE OF CONTENTS:
  1. · Building Rounded Corners With CSS and JavaScript
  2. · Our old friendly tables
  3. · The CSS approach
  4. · Working with fixed boxes
  5. · Nesting div elements
  6. · Using the DOM approach

print this article
SEARCH DEVARTICLES

Building Rounded Corners With CSS and JavaScript - Our old friendly tables
(Page 2 of 6 )

Being still present in so many websites, tables are intensively used to tackle the rounded corners effect. Since they are well-supported elements for the vast majority of browsers, using layout tables is the old-fashioned approach to solve the problem. Let’s see the code for that:

<table width="300" cellpadding="0" cellspacing="0">
<tr>
<td width="20"><img src="tl.gif" width="20" height="20" alt="" /></td>
<td width="260" bgcolor="#0000ff">&nbsp;</td>
<td width="20"><img src="tr.gif" width=20” height="20" alt="" /></td>
</tr>
<tr bgcolor="#0000ff">
<td width="20">&nbsp;</td>
<td width="260">Content goes here</td>
<td width="20">&nbsp;</td>
</tr>
<tr>
<td width="20"><img src="bl.gif" width="20" height="20" alt="" /></td>
<td width="260" bgcolor="#0000ff">&nbsp;</td>
<td width="20"><img src="br.gif" width="20" height="20" alt="" /></td>
</tr>
</table>

While it's still used widely across the Web, and was considered an acceptable approach a few years ago, now it’s rather an old solution, with plenty of useless and redundant markup for a decorative effect. The major drawback of using this technique is the problem that usually arises when images are inserted into tables. Small gaps and spaces will usually appear below the corner images, breaking down the table structure and making our rounded corners look very ugly and unprofessional.

The reason for this nasty effect is that images are “inline” elements, behave accordingly, and leave spaces between them and the cell boundaries where they are included. An easy approach to getting rid of the undesired artifact is to define that images within table cells will behave as “block” elements, instead of “inline” elements. Just including the proper CSS declaration within the stylesheet will fix the problem:

td img {
  display: block;
}

Setting the “block” element behavior for images will achieve the desired result. Also, Internet Explorer renders undesirable small gaps when inserting images into tables. If we have the following code:

<td>
<img src="tl.gif" width="20" height="20" alt="" />
</td>

the image won’t fit properly into the table cell. A quick fix for this is to restructure the code as follows:

<td><img src="tl.gif" width="20" height="20" alt="" /></td>

Now, the image will fit nicely into the cell. Pretty weird, huh?

The result for rounded corners with tables is shown in the next figure:

Building rounded corners with CSS and JavaScript

As seen previously, table-based rounded corners is still a viable solution for a few cases. But with the power of CSS, we can achieve the same effect without writing a lot of redundant markup, making our code tight and efficient.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




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