-
200618 Nov
Recently I had to code a box with rounded corners for a client, and I came up with a solution which works with 99% of the browser market and uses the CSS3 border-radius declaration for browsers which support it.
The simplified HTML code is:
<div class="curves top"> <img src="images/topl.png" width="10" height="10" alt=""/> </div> <div class="box"></div> <div class="curves bottom"> <img src="images/botl.png" width="10" height="10" alt=""/> </div>
The divs .top and .bottom will be hidden from browsers which support border-radius (or a proprietary implementation of it).
The basic CSS is:
div { margin: 0; padding: 0; width: 100px; background-color: #ff0000; } .box { min-height: 100px; -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; } .curves { display: none; }This will display a box 100×100 pixels with curved corners in Firefox and Safari, hiding the .top and .bottom divs and implementing border-radius.
To make it display in IE, we add some conditional comments with extra CSS which displays the .top and .bottom divs with four rounded corner images:
<!--[if IE]> <style type="text/css"> .box { min-height: 80px; } .curves { display: block; height: 10px; } .top { background: #ff0000 url('images/topr.png') no-repeat right top; } .bottom { background: #ff0000 url('images/botr.png') no-repeat right top; } </style> <![endif]--> <!--[if lt IE 7]> <style type="text/css"> .box { height: 80px; } <![endif]--> </style>The main drawbacks with this method are that the CSS won’t validate and it only works with fixed width boxes; however, a little recoding will fix this second problem.
Users of Opera and other browsers will see a square box; as my client is corporate and has never received a hit from an Opera browser, I was willing to make this sacrifice. If they ever implement -opera-border-radius I could add this in.
Of course there are other solutions for this, but I thought this way was quite simple.
You can skip to the end and leave a response.
-
Comments
-
01.
Doesn’t o-border-radius work? I do seem to recall they had something like this implemented…
-
02.
It seems that they used to support it, but I’ve tried both -o-border-radius and -opera-border-radius and neither works, so it looks as if they’ve removed support.
-
03.
What’s the point of doing it in CSS if you have inline presentational images in the mark-up? Seems like a big addition to the page weight.
-
04.
Because IE doesn’t support border-radius. It’s not intended to be a definitive solution, just to show a way that I used a CSS3 declaration.
-
05.
I think proprietary is the wrong to use term. Mozilla is open-source. I think you’re looking for non-standard
-
06.
Grimboy: It’s proprietary in the sense that the implementation, -moz-border-radius for example, is limited only to Gecko-based browsers. The way it’s implemented (-vendor_goes_here-property) is very much standard … the CSS spec has provisions for this method.
-
07.
-
08.
Now that Opera 9.5b is released, it still doesnt support CSS3’s border-radius property ?
-
09.
kosalaram says:Comment » February 24th, 2008 at 8:18 am
the rounderd borders in not working in IE6 & 7 what is the solution to use the code of css3 for border’s ?
-
10.
Here’s a variant that uses border-radius for Safari and FF3, with corner image fallback for IE7. Supports variable width boxes and the same HTML for both cases.
-
11.
-
12.
-
13.
I’ve read on one of Russian blogs that Opera supports SVG as a background. Try it for rounded corners!
-
14.
“border-radius will be supported from Presto 2.3 onward (ie after Opera 10, which is Presto 2.2 ”
-
01.
TAG CLOUD
acid3
advanced layout
advanced layout module
background
border
Browsers
color
css
CSS3.info
CSS WG
csswg
developer tools
disabled
enabled
Feedback
firefox
firefox 3.1
fonts
generated content
grid positioning
hixie
HSLA
HTML5
ie6
ie7
ie8
jina bolton
jquery
media player
News
Opera
Opera Dragonfly
presentations
RGBA
safari
Selectors
slides
SVG
text rendering
W3C
wasp
Web Fonts
webkit
windows

Leave a Comment