JavaScript
  Home arrow JavaScript arrow Page 3 - 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 
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 / 38
    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 - The CSS approach


    (Page 3 of 6 )

    CSS are great for implementing decorative effects that improve the overall presentation of a Web page. What’s more, they are remarkably powerful for achieving outstanding background effects within pages. Since rounded corners can be implemented as background images, instead of being directly inserted into documents with <img> tags, we’ll see how to make use of CSS extensive capabilities for manipulating background images, and finally obtain our desired effect.

    With CSS, a background image can be applied to any element of a page. Backgrounds can be manipulated in several ways to widely expand their visual impact.

    They can be repeated horizontally, vertically, or not repeated at all. Also, they can be positioned using absolute or relative measurements, fixed while page elements scroll, and positioned relatively to each corner of the element. A few simple CSS declarations will properly explain this:

    /* background image stays fixed */

    .fixed {
      background: #eee url(bg.gif) fixed;
    }

    /* background image repeats in x axis */

    .repx {
    background: #eee url(bg.gif) repeat-x;
    }

    /* background image repeats in y axis */

    .repy {
    background: #eee url(bg.gif) repeat-y;
    }

    /* background image repeats in x-y axis */

    .repxy {
    background: #eee url(bg.gif) repeat-x repeat-y;
    }

    /* background image not repeats */

    .norepeat {
    background: #eee url(br.gif) no-repeat;
    }

    /* background image locates at top left corner */

    .topleft {
    background: #eee url(br.gif) no-repeat top left;
    }

    /* background image locates at top right corner */

    .topright {
    background: #eee url(br.gif) no-repeat top right;
    }

    /* background image locates at bottom left corner */

    .bottomleft {
    background: #eee url(br.gif) no-repeat bottom left;
    }

    /* background image locates at bottom right corner */

    .bottomright {
    background: #eee url(br.gif) no-repeat bottom right;
    }

    Each CSS declaration rule shows clearly how a background image can be manipulated to obtain different effects. Although this is very basic for experienced designers, it can be handy for beginners.

    Whatever great flexibility stylesheets offer to designers, they still have some limitations about implementing background images.

    CSS2 imposes a significant limitation: it states that only one background image can be applied to each element of the page. Considering this restriction, we should tackle the problem of rounded corners by applying four different background images to different <div> tags, each corresponding to the corner we need to be rounded. If we’re designing with a “fixed layout” in mind, then we might embed only two images within two block-level elements, for instance <div>, <p> or headers tags, to easily get the rounded corners done.

    In the next section, we’ll see those possible alternative solutions.

    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...
       · What if your background image has a graient?
       · From the time I wrote this article, a few rounded corners techniques came up, which...
     

    JAVASCRIPT ARTICLES

    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page
    - Finishing a Slide Show Application with jQue...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT