<?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>Blue Arena &#187; fluid</title>
	<atom:link href="http://www.bluearena.com/tag/fluid/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bluearena.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 05 Jun 2010 17:23:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Rounded Corners and Fluid Boxes</title>
		<link>http://www.bluearena.com/2009/05/rounded-corners-and-fluid-boxes/</link>
		<comments>http://www.bluearena.com/2009/05/rounded-corners-and-fluid-boxes/#comments</comments>
		<pubDate>Fri, 22 May 2009 23:09:17 +0000</pubDate>
		<dc:creator>Maloric</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[corner]]></category>
		<category><![CDATA[corners]]></category>
		<category><![CDATA[cross]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[expand]]></category>
		<category><![CDATA[explorer]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[fluid]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[ie7]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[round]]></category>
		<category><![CDATA[rounded]]></category>

		<guid isPermaLink="false">http://wordpress.bluearena.com/?p=41</guid>
		<description><![CDATA[Rounded corners have long been a hot topic for web developers, with several methods out there, each with their benefits and disadvantages.  Although rounded corners seem to have fallen out of favour recently in favour of simple, clean designs, they still remain a powerful tool in any designer&#8217;s arsenal, which means knowing how to create [...]]]></description>
			<content:encoded><![CDATA[<p>Rounded corners have long been a hot topic for web developers, with several methods out there, each with their benefits and disadvantages.  Although rounded corners seem to have fallen out of favour recently in favour of simple, clean designs, they still remain a powerful tool in any designer&#8217;s arsenal, which means knowing how to create them is essential.  This tutorial will show you how to create tableless rounded corners than scale with fluid width and height, and can be expanded on to incorporate drop shadows or custom borders.<span id="more-41"></span></p>
<h2>What you need</h2>
<p>This tutorial assumes that you have a decent working knowledge of CSS and a little javascript (necessary if you want full IE6 support).  You&#8217;ll also need some sort of graphics editing software such as Adobe Photoshop or <a title="Go to the GIMP website" href="http://www.gimp.org/" target="_blank">the GIMP</a>.  I&#8217;ll be using Photoshop.</p>
<h2>Step 1: Design Your Box</h2>
<p><img class="alignleft size-medium wp-image-42" title="testbox" src="http://www.bluearena.com/wp-content/uploads/2009/05/testbox.gif" alt="testbox" width="197" height="126" />You&#8217;ll need to start off by creating an image of how your box will look when it&#8217;s finished.  For now I&#8217;m going to create a simple grey box with dark grey corners, something like the image you see here.  To create something similar simply draw a rectangle with rounded corners and add a 1px stroke.</p>
<p>It&#8217;s important that your box goes right to the edge of the image, so trim off any unneccessary white space.  You can save this as box1.gif.</p>
<h2>Step 2: The corners include</h2>
<p>The concept of this solution is to include four divs &#8211; one for each corner &#8211; that will be positioned absolutely within our both and styled appropriately.  Since this is the sort of technique that gets reused many times in the site, I prefer to create an include that contains all four corners.  Create a new file called &#8216;corners.html&#8217; and place the following markup inside:</p>
<pre>&lt;div class="tl corner"&gt;&lt;/div&gt;
&lt;div class="tr corner"&gt;&lt;/div&gt;
&lt;div class="bl corner"&gt;&lt;/div&gt;
&lt;div class="br corner"&gt;&lt;/div&gt;</pre>
<p>You&#8217;ll have noticed that each div has two classes.  The first just tells us which corner it is (top left, top right, bottom left and bottom right respectively).  The second lets us easily apply styles that all four corners will use.</p>
<h2>Step 3: The Box</h2>
<p>Let&#8217;s create the box and the markup we&#8217;ll need now, and then we&#8217;ll style it up once we&#8217;re done.  Where you want your box to appear, type the following code:</p>
<pre>&lt;div class="box1 corners"&gt;
    &lt;!--#include virtual='/path/to/corners.html'--&gt;
    &lt;div class="boxContent"&gt;
        &lt;p&gt;This is where your content will go&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;</pre>
<p>I&#8217;d better explain some of this.  The outer div is the box itself.  This will be styled to match your design and hads the extra class &#8220;corners&#8221; there to allow you to apply classes to all of your boxes, as well as making some of the javascript easier later.</p>
<p>Next is the corners include, which includes the four divs you created a moment ago.  Much nicer than including those manually every time, huh?</p>
<p>Last is a div called &#8220;boxContent&#8221;.  This is the div you&#8217;ll apply all of your padding to (allowing you to declare width:100% on the box itself without breaking anything).  It&#8217;s also useful to put overflow:hidden on the inner div to prevent the Firefox Float Bug if you float the contents of the box &#8211; this wouldn&#8217;t work on the outer box as the corners will need to be placed outside the box in order to work.  If all isn&#8217;t clear, don&#8217;t worry, just read on.</p>
<h2>Step 4: The CSS</h2>
<p>Ok, now for the fun part.  We&#8217;re going to start by styling up the basic box without rounded corners.  Basically what we need is a background colour, border and some padding.  Copy the following into your stylesheet:</p>
<pre>/* This allows us to position the corners relative to the box instead of the page */
div.corners { position:relative; }

/* This will make sure your corners never display over your content */
div.boxContent { position:relative; z-index:3; }

/* Styles specific to box1 */
div.box1 { color:#000; background:#E0E0E0; border:1px solid #666; }
div.box1 div.boxContent { padding:12px; overflow:hidden; }</pre>
<p>That&#8217;s it for the box.  Now for the corners.  They&#8217;re all going to be the same size and have many similar properties.  I like to create a seperate stylesheet for box/corner styles, but you&#8217;re welcome to put them where you like.</p>
<pre>div.corner { width:12px; height:12px; position:absolute; z-index:2;}
div.tl { top:-1px; left:-1px; background-position:top left; }
div.tr { top:-1px; right:-1px; background-position:top right; }
div.bl { bottom:-1px; left:-1px; background-position:bottom left; }
div.br { bottom:-1px; right:-1px; background-position:bottom right; }</pre>
<p>This has given us some universal corner styles.  Now we need to point our box 1 corners at the correct background image.  Add this line to your stylesheet and you&#8217;re good to go:</p>
<pre>div.box1 div.corner { background-image:url(/path/to/box1.gif); }</pre>
<p>Go on &#8211; check out your box now.  If you&#8217;re thinking that it can&#8217;t be that easy, think again.  You only had to cut out one image, not 4, and the box resizes perfectly in every modern browser.</p>
<h2>The Exception to the Rule</h2>
<p>Unfortunately if you&#8217;re using IE6 you&#8217;ll notice a rather frustrating bug.  If your box width or height is an odd number the bottom and right coordinates of your boxes will be 1px too short, meaning the border will show through.  There are two solutions.  The first uses javascript, and is my preferred method, to be covered in another post.  The second method involves only css:</p>
<p>The easiest way to fix the right coordinate is to fix the width of each box to an even number.  This isn&#8217;t too bad for fixed width sites, though could pose a problem for fluid layouts.  Unfortunately the bottom coordinate can&#8217;t be so easily fixed due to the fact that boxes should expand downward depending on the content.  So we need a more complex solution.</p>
<p>First, add the following line to corners.html:</p>
<pre>&lt;div class="btm corner"&gt;&lt;/div&gt;</pre>
<p>This div will be styled to mimic the bottom edge of the box.  We&#8217;ll need a background image for it, which will be a 2px or greater slice of the bottom of the box.  This will need to be repeated horizontally, so make sure there&#8217;s nothing else in the image.</p>
<p>Now you&#8217;ll need to change the &#8220;bottom&#8221; coordinate of your &#8220;bl&#8221; and &#8220;br&#8221; corners to -2px instead of -1px.  This means the corners will display 1px further down than they should.  This is where the &#8220;btm&#8221; div comes into play.  Add the following to your stylesheet:</p>
<pre>div.btm {
    height:12px;
    width:100%;
    bottom:-2px;
    left:-1px;
    background:url(/path/to/box1-btm.gif) bottom repeat-x;
    z-index:1;
}</pre>
<p>Now the bottom div will display 1px out the same as the corners, but because the three divs cover the bottom edge of the box, you can&#8217;t see the discrepancy, providing a CSS only solution to the problem.  Note that the bottom div needs to be placed below the two corners, hence a z-index of 1.</p>
<h3>Next time: A Javascript Solution</h3>
<p>Next time we&#8217;ll look at fixing the IE6 problem using JQuery to reposition the corners depending on the width of their parent.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bluearena.com/2009/05/rounded-corners-and-fluid-boxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
