- [720.381.2433
- contact form]
Rounded Corners - CSS3 for You and Me
Download Code | View Source
I'm currently working on a website for the University of Colorado at Boulder (more details to come on this project) and I ran into a common problem amongst web developers, rounded corners. Sure you may think they look snazzy and coding them can't be that hard, which thanks to the new CSS 3 standards you would be correct on both accounts in a perfect world. Unfortunately we live in a world that uses Internet Explorer (IE). None of the current versions of IE support CSS 3 standards.
Let IE Suffer
I ran across an article explaining a great way to tackle this problem but unfortunately it didn't seem to work the way I had hoped. So I decided to do it the old school way in IE and use images for IE only. To accomplish this I used an IE only style sheet and placed the image replacement in there.
So to outline this you place a comment in your html head with your other style sheets like this:
<!--[if IE]>
<link type="text/css" rel="stylesheet" media="all" href="ui/css/ie.css" />
<![endif]-->
Then in the body setup your div like this:
<div id="main"> <!--[if IE]>
<div id="main-tr"> <div id="main-bl"> <div id="main-br"> <![endif]--> <p>Content here</p> </div><!--[if IE]> </div></div></div> <![endif]-->
You will notice that all of the extra divs that we have to create are surrounded by a conditional comment so they will only be read by IE. This code will be a bit bloated for IE but will take advantage of CSS 3 and will run much smoother for Firefox, Safari, and Chrome without the bloat. Here's the code for a style sheet that is seen by all browsers:
#main{
background:#ddd;
height:100px;
width:960px;
padding:10px;
/* Select all four corners for the possibility of
controling larger radius or only rounding certain corners */-webkit-border-top-right-radius: 10px; /* for Safari */
-webkit-border-top-left-radius: 10px; /* for Safari */
-webkit-border-bottom-right-radius: 10px; /* for Safari */
-webkit-border-bottom-left-radius: 10px; /* for Safari */
-moz-border-radius-topright: 10px; /* for Firefox */
-moz-border-radius-topleft: 10px; /* for Firefox */
-moz-border-radius-bottomright: 10px; /* for Firefox */
-moz-border-radius-bottomleft: 10px; /* for Firefox */
}
This can be accomplished by two lines but I did it the previous way to show you how to select each corner one by one. Here's a two liner:
#main{
background:#ddd;
height:100px;
width:960px;
padding:10px;
-webkit-border-radius: 10px; /* for Safari */
-moz-border-radius: 10px; /* for Firefox */
}
Once you have the corners working with CSS3 you can open it up in firefox or safari and take a screenshot. Then open the screenshot in photoshop and grab each corner and save them individually. I named them each:
- main-tl.jpg
- main-tr.jpg
- main-bl.jpg
- main-br.jpg
Then place them in an images folder within the css folder. From there you can place the proper css inside the ie.css:
#main{
background:#ddd url(images/main-tl.jpg) top left no-repeat;
}
#main-tr{
background:url(images/main-tr.jpg) top right no-repeat;
}
#main-bl{
background:url(images/main-bl.jpg) bottom left no-repeat;
}
#main-br{
background:url(images/main-br.jpg) bottom right no-repeat;
height:100px;
width:960px;
}
This will work in all versions of ie including the well hated ie6, see my post on ie6 for further hate. So now you have a very sleek CSS3 solution for rounded corners that will also work in all versions of IE. This is definately bloated for IE but there's no way around using images or javascript in order to make your code happy in IE. The Pinnakl website currently uses javascript for the rounded corners which we may change some day soon. If someone has a different technique they use, please let us know in the comments.
Comments
Post new comment