Rounded Corners (Method 2)

Written by Mat on Friday, March 16, 2007 12:12 - 0 Comments

OK, so if you’ve tried my previous version of the rounded corner box, you’ll note that it has a few limitations:

  • the width of the box is limited to the size of the right-side images,
  • there are occasional hiccups in the code that cause the lower left image to not reach the bottom corner, and
  • it still requires manual imagery

So here’s another way you can consider tackling it.  OK, so we’re borrowing a piece of (LGPL) code from another developer but I have successfully implemented this approach in several places, including this site.

Visit curvycorners.net to download the components you’ll need.  After that it’s pretty simple.  The code itself is DHTML so it combines a nice piece of Javascript with your XHTML-based code.  Essentially it vectors the borders of your DIVs and rounds them out mathematically.

To begin, first add the script to your code:

<script type=”text/JavaScript” src=”rounded_corners.js”></script>

Next, create the DIV container that you want to add the rounded corners to:

<div id=”roundedDiv”></div>

Finally, in the <HEAD> portion of your HTML, add the following:

<script type=”text/JavaScript”>
  window.onload = function()
  {
    settings = {
      tl: { radius: 10 },
      tr: { radius: 10 },
      bl: { radius: 10 },
      br: { radius: 10 },
      antiAlias: true,
      autoPad: false
    }
    var divObj = document.getElementById(“roundedDiv”);
    var cornersObj = new curvyCorners(settings, divObj);
    cornersObj.applyCornersToAll();
  }
</script>

What I really like about this nifty code snippet is that it is extremely flexible:

  • turn the rounding on or off on a per-corner basis
  • each corner can have its own radius
  • anti-aliasing can be turned on or off
  • you can round corners on multiple DIVs by ID or class

Download it, set it up and mess around with it.  One side note – there was a question at one point on how to implement a shadow for the box once you’d rounded it off.  THINK!  There’s two easy ways to do this – you can either script a second div that falls behind it offset by a few pixels, or you can use a shadow filter in your CSS.  Students in the upcoming IMD223 (Advanced Scripting) – we’ll be learning how to do this!

By the way, like most GPL and LGPL scripts, if you end up implementing it, do the right thing and donate to the cause – this type of social morality is what keeps good code out on the Internet and available for developers like us to use.

Share this post on digg, del.icio.us, facebook, blah blah blah


Leave a Reply

Comment

SocialStuff

RSS Feedburner LinkedIn Twitter Delicious Jen's MadeByGirl Blog

Quick Lists

  • Art Institute of Las Vegas
  • IMD123: Program Logic »
  • IMD213: Intermediate Scripting (SP09) »
  • IMD223: Advanced Scripting (SU08) »
  • IMD322: Dynamic Design (WI09) »
  • IMD325: User Centered Design (WI09) »
  • IMD335: Usability Testing (SP09) »
  • IMD335: Usability Testing (SP08) »
  • IMD345: UCD Integration (SU08) »
  • IMD375: Databases (FA09) »
  • IMD402: Server-Side Technology (WI09) »
  • Independent Studies (SU08) »
  • University of Nevada, Las Vegas
  • INF400: Web Security »
  • INF340: Web Design Concepts »

Yummy Delicious

Meanwhile on Flickr ... [Design//Diseño Pool]

sweet
CHINA
Ejercicio Caligrama Illustrator
Ejercicio Pincel Illustrator
Ejercicico Degradados Illustrator
Ejercicio Malla Illustrator
Ejercicio Cubos Photoshop
Hallelujah
Comus, 1921
Enjin Guild Hosting

Reading Recommendations



Soapbox

Sep 2, 2010 10:08 - 0 Comments

HTML5 Video on IE9

More In Soapbox


IMD414 Dynamic Design

Jun 14, 2010 14:36 - 0 Comments

The Local Maximum

More In IMD414 Dynamic Design


INF400 Web Security

Mar 24, 2010 22:16 - 0 Comments

Save UNLV Informatics

More In INF400 Web Security