JavaScript
  Home arrow JavaScript arrow Page 4 - 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 - Working with fixed boxes


    (Page 4 of 6 )

    If we’re working with a “fixed layout” where the width of the element to which we’re applying rounded corners is fixed, let’s say 300 pixels, then we can easily create two different images: one applied to the top section of the box, and the other to the bottom section, respectively. Next, we nest the containing elements to achieve the desired effect. Let’s see the following example to understand this technique.

    First off, let’s declare our style rules:

    <style type="text/css">
    .rounded {
      width: 300px;
      background: #00f url(imgbottom.gif) no-repeat bottom center;
      padding-bottom: 40px;
    }
    div.rounded h2 {
      background: transparent url(imgtop.gif) no-repeat top center;
      padding-top: 40px;
    }
    </style>

    Then, let’s write our markup:

    <div class="rounded">
    <h2>Title section here</h2>
    <p>More content</p>
    <p>More content</p>
    <p>More content</p>
    </div>

    We’ve defined a class named “rounded,” and its width is set to 300px (fixed size). A background image is set to locate at the bottom section of the element. With the next rule, we’re defining that any h2 element contained within the “rounded” div class will have a background image located at the top of that <h2> tag.

    Since the <h2> element is located on the top of the box, it’s easy to apply a background image that obviously will be positioned at the top of the <h2> element, and apply the other image to the bottom of the containing <div>. Our rounded corner effect is finally achieved.

    The visual output for this technique is presented below:

    Building rounded corners with CSS and JavaScript

    The above explanation would be incomplete without the corresponding background images used for the top and the bottom section of the box. Here they are:

    The top image:

    Building rounded corners with CSS and JavaScript

    and the bottom image:

    Building rounded corners with CSS and JavaScript

    That looks pretty good, right? The same effect is reached with CSS and minimal markup, due to its excellent capabilities for manipulating background images.

    As said so many times, a picture is worth thousand words, so let’s see a simple diagram that shows how the above technique works, for the sake of clarity:

    Building rounded corners with CSS and JavaScript

    Documents that contain a well-defined structure, properly built to maintain the correct page’s hierarchy, are great for this technique, achieving high-impact visual effects for multiple page elements while keeping the correct internal markup structure.

    Building rounded corners with four different backgrounds is our final goal, so let’s present another technique for getting a little bit closer to our main purpose.

    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 4 hosted by Hostway
    Stay green...Green IT