Free tech support header

How do I create CSS3 rounded corners and drop shadows?

I want to start experimenting with CSS3 on my Web site and would like to start with rounded corners and drop shadows, both of which would be mondo cool to include on my site. Is it too soon? If not, how do I create CSS3 border radius containers?


Dave's Answer:

Ah, the ugly mess that is the evolution of Web standards. Whether it's HTML5 or CSS3, both are slowly and painfully becoming standards, but in the meantime, it turns out that there's much debate and contention about even the simplest of features.

Like rounded corners.

In the CSS3 spec, rounded corners are specified as border-radius: though it's implemented differently in the Mozilla family of browsers (including Firefox) than the Webkit (Safari) group.

What this means is that if you're running, say, Internet Explorer or an older version of one of these browsers, odds are good you won't see anything happen when you specify the right CSS attribute.

Here's an example:

This should be a box with nicely rounded corners.

The code for this to work is:

<div style="background-color:#ccf;padding:8px;border:2px solid black;border-radius:10px;">This should be a box with nicely rounded corners.</div>

Not too bad to use, but why they can't just accept "border-radius", well, that's part of the adventure of web standards, I suppose.

Now, what about a drop shadow? That's done with the css attribute box-shadow, which takes three parameters: horizontal offset of the shadow, vertical offset of the shadow, blur factor and color. Complicated, eh?

Here's how it could be used in cooperation with the earlier rounded box:

This should be a box with nicely rounded corners.

Bet there's no shadow, though. Turns out that there's great debate about how to implement box shadow, so in fact you need to match the CSS3 model of your browser for it to even have a possibility of working.

Like this:

This should be a box with nicely rounded corners and a drop shadow.

Did that work for you? If you're on a modern browser it probably did. Cool, right? Yeah, except here's the CSS3 required to make this work:

Here's the code I'm using for this to work:

<div style="background-color:#ccf; padding:8px; border:2px solid black; border-radius:10px; box-shadow: 8px 8px 4px #666;-o-box-shadow: 10px 10px 5px #888;-icab-box-shadow: 10px 10px 5px #888;-khtml-box-shadow: 10px 10px 5px #888;-moz-box-shadow: 10px 10px 5px #888;-webkit-box-shadow: 10px 10px 5px #888;box-shadow: 10px 10px 5px #888;">This should be a box with nicely rounded corners and a drop shadow.</div>

More than a bit of work, but at least it does render properly in modern browsers, and that's pretty darn slick.

Keep track of what's happening in the world of CSS3 by tracking http://www.css3.info/ too.



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon    

Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments
Rather amazingly, there are no comments on this article yet.

I have something to say, now that you mention it, but ...
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.






Recent Entries
Search
I Need Help!



Join The Club!
Sign up and get free weekly updates, news on my speaking schedule, seminars, workshops and more. It's cool. Just do it. :-)

© 2002 - 2010 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.