JavaScript
  Home arrow JavaScript arrow Page 2 - Building Rounded Corners With CSS and Java...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Building Rounded Corners With CSS and JavaScript
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 36
    2005-01-03

    Table of Contents:
  • Building Rounded Corners With CSS and JavaScript
  • Our old friendly tables
  • The CSS approach
  • Working with fixed boxes
  • Nesting div elements
  • Using the DOM approach

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More JavaScript Articles
    More By Alejandro Gervasio


       · As I've seen trough this article, building rounded corners that way is quite easy...
       · Nice article.I can see the smoothness in using JavaScript to make rounded corners,...
       · I liked the break-down a lot, and even though i think I'm gonna stay with the...
       · Hello,I think your point is good. The reason of having that Javascript design is...
       · Hello,Thank you for the comments. I agree about using only CSS for background...
       · the article is fine ...except for the need for gifs for each corner...i am sure...
       · Hi, Thnk you for the comment! I could have included the corner images, but I...
       · he was talking about the fact that you need .gif files at all to create this rounded...
       · Don't mean to cause problem, but right before your entry in google is...
       · If it's a decoration that your IE users can do without then you can make this easy....
       · Thanks for the comments on the article.Regarding the article that you...
       · Hi, I didn´t know about this technique. Thank you for sharing it. I think that it...
       · would be nice if he posted a solution how to create rounded corners without...
       · > Thnk you for the comment! I could have included the corner images, > but I...
       · Thank you for posting your comments here, and I hope you enjoy working with rounded...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT