<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BestInClass.com Blog &#187; Development</title>
	<atom:link href="http://www.bestinclass.com/blog/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestinclass.com/blog</link>
	<description>Behind BestInClass.com's recommendation service</description>
	<lastBuildDate>Fri, 28 Aug 2009 23:43:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple CSS3 rounded corners with support for IE</title>
		<link>http://www.bestinclass.com/blog/2008/css3-border-radius-rounded-corners-ie/</link>
		<comments>http://www.bestinclass.com/blog/2008/css3-border-radius-rounded-corners-ie/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 00:08:15 +0000</pubDate>
		<dc:creator>Bill Lipa</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.bestinclass.com/blog/?p=14</guid>
		<description><![CDATA[Rounded corners are a common element of web designs.  Unfortunately, they have been frustratingly difficult to express in clean CSS / HTML.  The long term solution is CSS3&#8217;s border-radius property, which is nicely supported in the current versions of Safari and Firefox.  Sadly but unsurprisingly, this property is not supported in IE, [...]]]></description>
			<content:encoded><![CDATA[<p>Rounded corners are a common element of web designs.  Unfortunately, they have been frustratingly difficult to express in clean CSS / HTML.  The long term solution is CSS3&#8217;s border-radius property, which is nicely supported in the current versions of Safari and Firefox.  Sadly but unsurprisingly, this property is not supported in IE, even the upcoming IE8.</p>
<p>The new design for our website was full of rounded corners.  As an avid Firefox user, I simply could not bear the idea of sending millions of little corner images when border-radius did the trick so well.  Yet, IE7 is the dominant browser, so we couldn&#8217;t leave those users out in the cold.</p>
<p>I started looking for a technique that would meet these requirements:</p>
<ul>
<li>CSS3 border-radius aware browsers are sent clean, fast CSS with no corner images</li>
<li>IE7+ gets a fallback using corner images</li>
<li>The same HTML is used for all browsers &#8211; only the CSS is different</li>
<li>Cosmetics in IE6 don&#8217;t matter &#8211; it&#8217;s OK to have square corners in this old browser</li>
<li>No Javascript</li>
</ul>
<p>Fortunately, I did find a flexible way to achieve this without too many problems.  If you look at the <a href="http://www.bestinclass.com">BestInClass.com home page</a> in Firefox, all of the corners and rounded buttons are implemented with pure CSS3.</p>
<p><span id="more-14"></span></p>
<p>The main drawbacks and restrictions are:</p>
<ul>
<li>It adds some non-semantic empty divs to the markup.</li>
<li>It requires a way to deliver different CSS to IE.</li>
<li>It cannot support rounded elements with a border that sit on top of unpredictable backgrounds.</li>
</ul>
<h4>Show Me, Don&#8217;t Tell Me</h4>
<p>For those that want to skip over the why and get straight to the how, here&#8217;s a fairly minimal example in a single file.</p>
<p><a href="http://www.bestinclass.com/blog/samples/css3-rounded-corners-ie/example.html">CSS3 Rounded Corners With IE Fallback Example</a></p>
<h4>The Code for Decent Browsers</h4>
<p>The first thing to do is pick a unique style id for the rounded corners.  This id will be used to find the right corner images for IE, so it needs to be unique considering the rounded block&#8217;s background color, border style, and background the block is sitting on top of.</p>
<p>First, the HTML.  Wherever we want to have a rounded block, use the following elements:</p>
<pre class="code">
&lt;div class="rounded_STYLE rounded"&gt;
  &lt;div class="tl"&gt;&lt;/div&gt;&lt;div class="tr"&gt;&lt;/div&gt;
  ... contents of the block go here ...
  &lt;div class="bl"&gt;&lt;/div&gt;&lt;div class="br"&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>STYLE should be the unique style ID you chose.  The empty tl and tr divs are the top left and right corners, while the bl and br are the bottom right.  Those divs are not used at all in a CSS3-aware browser, but they are needed for IE&#8217;s image corners.</p>
<p>For a CSS3 aware browser like Safari and Firefox 3, this element can be styled very simply:</p>
<pre class="code">
.rounded_STYLE
{
    background-color: COLOR;          /* if needed */
    border: 1px solid BORDER_COLOR;   /* if needed */
    -webkit-border-radius: RADIUS;    /* for Safari */
    -moz-border-radius: RADIUS;       /* for Firefox */
}
</pre>
<p>RADIUS would be something like 4px.  And that&#8217;s it, you&#8217;re done in Firefox and Safari.</p>
<h4>The Code for IE</h4>
<p>Life would be good if we could stop there, but unfortunately the depressingly incomplete and non-standard IE remains the favorite of a majority of users&#8230;  At least usage of IE6 has dwindled to the point where we no longer have to worry about pixel perfection there.  And that opens the door for a decent solution in IE7 and above.</p>
<p>Did I mention that the HTML is the same?  Yes I did.  But we do need different CSS.  Somehow, you need to hide the CSS for .rounded_STYLE above from IE, and feed it the following instead.  On BestInClass.com we use dynamically generated CSS to do this, but you could use IE conditional comments as well.</p>
<pre class="code">
.rounded_STYLE
{
  background-color: COLOR;            /* if needed */
  border: 1px solid BORDER_COLOR;     /* if needed */
  position: relative;
}

.rounded_STYLE &gt; .tl, .rounded_STYLE &gt; .tr, .rounded_STYLE &gt; .bl, .rounded_STYLE &gt; .br
{
  width: RADIUS;
  height: RADIUS;
  position: absolute;
}

.rounded_STYLE &gt; .tl
{
  background: url(/images/ui/rounded/STYLE-tl.png) top left no-repeat;
  top: OFFSET;
  left: OFFSET;
}

.rounded_STYLE &gt; .tr
{
  background: url(/images/ui/rounded/STYLE-tr.png) top right no-repeat;
  top: OFFSET;
  right: OFFSET;
}

.rounded_STYLE &gt; .bl
{
  background: url(/images/ui/rounded/STYLE-bl.png) bottom left no-repeat;
  bottom: OFFSET;
  left: OFFSET;
}

.rounded_STYLE &gt; .br
{
  background: url(/images/ui/rounded/STYLE-br.png) bottom right no-repeat;
  bottom: OFFSET;
  right: OFFSET;
}
</pre>
<p>Here RADIUS is again something like 4px and STYLE is the unique corner style id you chose.  OFFSET should be set to -1px if you have a 1 pixel border for the element, or 0 if there is no border.</p>
<p>The CSS references four different corner images.  In this example, they are located on the path /images/ui/rounded.</p>
<h4>Making the Corner Images</h4>
<p>You could generate these images using PhotoShop or another image editor.  At least on a Mac, there is a much easier way for the non-PhotoShop savvy using the Preview application.</p>
<ol>
<li>Display your page in Firefox and take a screenshot of one of the corners.</li>
<li>Open the screenshot in Preview.  Zoom in so that you can see the pixels clearly.</li>
<li>Select a square that is no bigger than RADIUS on a side and which is aligned with the straight borders of the element.</li>
<li>Copy and New from Clipboard.</li>
<li>Save this corner in your /images/ui/rounded directory using the name STYLE-CORNER.png where CORNER is tl, tr, bl, or br depending on whatever corner you chose.</li>
<li>Use Flip Horizontal and Flip Vertical to generate the other three corners and repeat.</li>
</ol>
<p>Congratulations, you should now have attractive anti-aliased rounded corners in all modern browsers, with Firefox and Safari users able to enjoy faster browsing without millions of teeny corner images clogging up the internets.  Plus, you have the satisfaction of being future-compliant with CSS3 as it becomes increasingly available.</p>
<p><strong>Update 3/10/2009:</strong> Note that if you make your corner images for IE some other way than the suggested screenshot method above, that the background should not be transparent.  Otherwise the square border that IE places down will not be erased properly.  Also, all of the images should be the same square size.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bestinclass.com/blog/2008/css3-border-radius-rounded-corners-ie/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
	</channel>
</rss>
