Full Version: Rounded Corners Without Images!
Dream.In.Code > Programming Tutorials > CSS Tutorials
Speechist
There is a cool way to get rounded corners on your containers (DIV or whatever) of almost any size/dimension (radius) without using a single image. The good folks at Mozilla have provided us support for this CSS standard (sorry, IE hasn't caught up to this yet, and I'm not sure IE7 will either...if someone has newer info on this, please post).

The code is actually painfully simple. Just define the amount of radius you want for a given corner of a container's style declaration:

CODE
#inner {
    width:200px;
    float:left;
    margin-right:2%;
    border:3px solid #D6D6C2;
    background:#E0E9F8;
    padding: 3px;
    font: 12px Verdana, Arial, Helvetica, sans-serif;
    -moz-border-radius: 15px 0 15px 0;
}


Of course in the
CODE
<body>
you would attach the #inner declaration to a DIV:
CODE
<div id="inner">Here is some content</div>
or other container element.

In this instance, we've defined an ID declaration called "inner" with a certain width, floated it left, gave it a bit of a margin all around, a border, padding and a font. But if you look closely at the last item, you'll notice a definition for the amount of radius for the border. The convention here for the 4 numbers is: upper-left, upper-right, lower-right, lower-left. In this case, we've got a nice 15px radius on the upper-left and lower-right corners. Cool! To see this in action, take a look at the following page:


RRHS B & E Academy

Be sure you're looking at this in Firefox to see the effect. In IE, it just ignores the code and renders nice square corners. Very imaginitive Bill.

Anyway, have fun with this and keep hoping IE will catch up some day!
im@geek
Will this work with Safari?
im@geek
I answered my own question, Yes this does work with safari!
danielle_1_uk
QUOTE(Speechist @ 25 Feb, 2006 - 04:50 AM)
Be sure you're looking at this in Firefox to see the effect.  In IE, it just ignores the code and renders nice square corners.  Very imaginitive Bill.

Anyway, have fun with this and keep hoping IE will catch up some day!

Nice!

I am all for cross-browser compatibility but instead I'm going hope that IE maintains its Fischer-Price "My first Browser" status...and feel safe in the knowledge that more and more people are beginning to realise this.

EDIT: At least mozilla use "-moz-" as a prefix for all their proprietary CSS properties and values, which follows the W3C's standards. But of course, IE doesn't adhere to this - Microsoft it seems choose to name their vendor specific tags anything they feel like mad.gif

For a few more mozilla ones, and how they're supported, check out:
http://www.blooberry.com/indexdot/css/prop...sextensions.htm

...roll on CSS3
michelle@urban
QUOTE(danielle_1_uk @ 25 Mar, 2006 - 09:15 PM)
I am all for cross-browser compatibility but instead I'm going hope that IE maintains its Fischer-Price "My first Browser" status...and feel safe in the knowledge that more and more people are beginning to realise this.

I sure hope so! The whole cross compatibility thing between IE and Firefox from a graphics point of view is just a pain in the arse, is there anyway to make them view the page the same way? NO! Arghhhh.

Down with IE tongue.gif
Arbitrator
The caveat to using this property is that any background image you use will not be rounded by this property; the background will still have the normal 90 degree angular corners that you're used to except that it'll look out of place with the rounded corners. This effectively limits you to using a solid color background, a transparent background, or a pre-built image to match the current rounded borders. Also, you need to specify padding that exceeds the space subtracted from the corners or your box contents will overlap the border in this area.

It should also be noted that this is a Mozilla-specific CSS property. As such it should work in any Mozilla-based browser such as Firefox and Netscape. If it works in Safari, that must be based on Mozilla as well.

The property is based on the W3C's CSS3 Backgrounds and Borders Module: Border Radius which is currently in draft status, so you can't blame Internet Explorer for not supporting it. Browsers aren't required to support specifications until they reach the status of "recommendation". Also note that the Mozilla implementation doesn't actually match the specification either.

Of course, this code shouldn't really hurt anything so there shouldn't be any problems using it as long as you keep in mind that only Mozilla users will see it.
MsAne
wow this is real neat, theres alot of other neat things in css but ofcourse we always have the broswer compatibility issue GRRRRRRRRRRRRRRR!
shweta.honey25
hi its working on safari,firefox but not working on IE6
give reason and solution plz that why its not working
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.