Navigation Menu
Alphabetical Listing
Site Contents

Site FAQ
About JSS
JavaScript Forum
JavaScript Tutorial
Friends of JSS

Link to Us
JavaScript Help
Contribute a script
Technology Jobs

Become a Partner

Internet.commerce

Be a Commerce Partner














Internet.com

IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

Developer Channel

FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

Great Sites

DocJavaScript.com
dhtml.com
The Freebie Directory
TheFreeSite.com

Browse Doc JS's Tips!


Hiermenus Central


Promotions

Free Announcements


Social Bookmark

General

This script permits rounded corners to be applied to DIV elements. The corners and associated edges are added to the initial DIV dimensions. There may be as many applications on a page as needed.





Notes

All variable, function names are prefixed with 'zxc' to minimise conflicts with other JavaScripts. This prefix can be safely changed to characters of choice using global find and replace.

The requirement for the rounded corners is defined within the DIV class attribute as a fake rule. Note that more than one rule may be specified in a class attributeso long as the rules are separated by a space.

The 'corner rule' is to be specified as in the example:


  <div id="tst2" class="tst zxc,Rad20,Border2#FFCC66,
    TLTR,Opacity50" style="width:200px;height:100px;
      left:280px;top:100px;">

where 'zxc' allows the script to recognise that rounded corners are to be applied. The balance defines the corner features, each feature separated by a comma:

  • Rad = the radius of the corners.
  • Border = (optional) the border size and color.
  • TLTRBLBR = (optional) the corners to apply the rounded corner, LT = Top Left etc. The default is all corners.
  • Opacity = (optional) the opacity id the DIV including corners.

Note that if the DIV inline border style attribute is defined in the DIV tags, the border will be applied to all four corners unless otherwise specified in the DIV fake class rule.

Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: roundedCorners.js


CSS

Paste this code into your external CSS file or in the <style> section within the HEAD section of your HTML document.


Head

Paste this code into the HEAD section of your HTML document.


Body

Paste this code into the BODY section of your HTML document


User Comments

Add a comment, suggestion, or correction
[For questions about usage, consult the Notes tab above or visit the JavaScript forum. Do not include more than two (2) lines of code in your comments. If you have suggestions or corrections, you can submit them to us.]

    
   
       
[optional]
 
[optional]

   

Comments feed Comment Feed RSS 2.0

11. From: Steamboat
09/29/2008 02:51:26

Hmm.. it doesn't work with widths in percent.

9. From: blogger tools
04/17/2007 20:03:55

works perfectly in firefox2, but it generates activeX warning messages in IE7

10. From: Lee (Admin)
05/25/2007 11:33:34

You need to check your security settings for IE7. It works fine for me.

8. From: Paul D
03/06/2007 14:58:59

bottom corners dont render correctly in IE7........but are perfect in Firefox ( need cross browser update)

7. From: Phillip Juan McClore
02/22/2007 10:24:25

What could be causing jagged edges on the bottom left and right? The border is too long. Otherwise its excellent, and if I have to, I could only use the tops

6. From: Michael B
02/16/2007 14:10:45

Nice. If the code/implementation confuses you, the same thing can be done in CSS with much less code, and it works even with Javascript disabled.

5. From: Satyabrata Choudhury
02/15/2007 18:05:55

works on Firefox 2 and IE 7. Excellent script. Thanks.

4. From: Kumar S
02/13/2007 01:13:52

The right and left borders are extended in IE7

3. From: Amer Neely
02/11/2007 10:01:58

Tried the round corners script in Firefox, IE and Opera. Only Firefox seemed to render it correctly.

2. From: Vibhu Bansal
02/10/2007 01:32:34

Amazing script...does away with need to have transparent gif for rounded corners effect.

next comments...

Do you write JavaScripts?
If you do, why not submit them to us?
We'll give you credit and a link back to your Web site.