<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Raised By Turtles&#187; clearfix</title>
	<atom:link href="http://raisedbyturtles.org/tag/clearfix/feed/" rel="self" type="application/rss+xml" />
	<link>http://raisedbyturtles.org</link>
	<description>None of the News that's Fit to Print</description>
	<lastBuildDate>Wed, 09 May 2012 01:51:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Bailing Your Boat: Clearing Problem Floats</title>
		<link>http://raisedbyturtles.org/smarter-css-floats/</link>
		<comments>http://raisedbyturtles.org/smarter-css-floats/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 23:12:10 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[clearfix]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[floats]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://raisedbyturtles.org/smarter-css-floats/</guid>
		<description><![CDATA[Floats can be incredibly frustrating when they don't work as you expect and they often don't. The normal way allows for you to create drop caps, meaning the floated element sticks out beyond the borders of the containing box. Usually, though, you don't want that when building web layouts and there are better ways to fix it than by adding an element with clear:both; Here's one good method and a comprehensive list of links on the subject.]]></description>
			<content:encoded><![CDATA[<p>CSS floats can present some elegant solutions… and some aggravating problems. Most of the problems relate to intelligently clearing a float. What follows are brief descriptions of a few methods for handling the problem.<span id="more-21"></span> <strong>There is nothing new here</strong>. Everything here I got from somewhere else where it is described better and in more detail and with better illustrations. <strong>This page is just for my reference </strong>so I won&#8217;t forget and won&#8217;t have to keep looking this up because sometimes I go ages without having to deal with this, and then I forget.</p>
<p>If you want to go to the source on this, check out these articles:</p>
<ul>
<li>Ed Eliot has a <a href="http://www.ejeliot.com/blog/59">nice summary of various clearing methods</a> as well as a <a href="http://www.ejeliot.com/samples/clearing/rule-support.html">browser support chart</a> for each method. The clearest explanation anywhere.</li>
<li>Phrogz.net has a nice<a href="http://phrogz.net/css/understandingfloats.html"> basic overview on understanding floats</a>, but not as in-depth as some others.</li>
<li>An old article by CSS guru Eric Meyer has an excellent explanation of the way floats work and perhaps the original explanation of the <a href="http://www.complexspiral.com/publications/containing-floats/">nested float method</a>. I found this article years ago and then forgot it and had to look it up again. Thus this article where I&#8217;ll know where to find it.</li>
<li>Smashing Magazine has a comprehensive<a href="http://www.smashingmagazine.com/2007/05/01/css-float-theory-things-you-should-know/"> overview of float tips</a>, including the various clearing methods. This article is pretty heavily linked and will get you to a bunch of other resources. Max Design also has a number of <a href="http://css.maxdesign.com.au/floatutorial/">CSS float &quot;recipes&quot;</a> (my term).</li>
<li>Shaun Inman uses <a href="http://www.shauninman.com/archive/2006/05/22/clearance_position_inline_absolute">absolute positioning and javascript</a> to avoid float idiosyncracies altogether.</li>
<li>Tony Aslett developed the   <a href="http://csscreator.com/?q=attributes/containedfloat.php">clearfix:after</a> solution which is also discussed in detail at <a href="http://www.positioniseverything.net/easyclearing.html">Position Is Everything</a>. This is broken by IE7 unless you do something to <a href="http://www.tanfa.co.uk/archives/show.asp?var=300">trigger HasLayout</a>.</li>
<li>Finally, there are several articles from 2005 or so on the overflow:hidden solution. The original idea is actually part of the  <a href="http://www.w3.org/TR/CSS21/visudet.html#root-height">CSS spec on height and &#8216;auto</a>&#8216; and was picked up and publicized by <a href="http://www.sitepoint.com/blogs/2005/02/26/simple-clearing-of-floats/"> Alex Walker</a> drawing on Paul O&#8217;Brien&#8217;s wisdom. Further refinements have been offered by Peter-Paul Koch over at quirksmode.org (<a href="http://www.quirksmode.org/css/clearing.html">CSS &#8211; Clearing floats</a>). It was also picked up by my old friend Mike Papageorge (<a href="http://www.fiftyfoureleven.com/weblog/web-development/css/simple-clearing-of-floats">Simple Clearing of Floats</a>) who is still waiting patiently for the ski site I announced in 2002, and from there was found by the folks at 456 Berea Street (<a href="http://www.fiftyfoureleven.com/weblog/web-development/css/simple-clearing-of-floats">Simple Clearing of Floats</a>). </li>
<li></li>
</ul>
<h2>Normal Floats</h2>
<p>So normally, you want a float to have all subsequent text to flow around it. That&#8217;s exactly what you want.</p>
<div style="border: 1px solid black; width: 50em">
<p style="float: left; width: 8em; background-color:#ddd; margin-right:1em; "><strong>Float Your Boat Gently Down the Stream: the case of normal floats. Merrily, merrily, merrily, floats are but a dream</strong></p>
<p>To my right is a sort of title box like when magazines excerpt something. I&#8217;m not floated. Im&#8217; just regular old text about floats.</p>
<p>Row row row your boat, gently down the stream, merrily merrily merrily life is but a dream. Row row row your boat, gently down the stream, merrily merrily merrily life is but a dream.Row row row your boat, gently down the stream, merrily merrily merrily life is but a dream.Row row row your boat, gently down the stream, merrily merrily merrily life is but a dream.Row row row your boat, gently down the stream, merrily merrily merrily life is but a dream. Row row row your boat, gently down the stream, merrily merrily merrily life is but a dream.Row row row your boat, gently down the stream, merrily merrily merrily life is but a dream. Row row row your boat, gently down the stream, merrily merrily merrily life is but a dream.Row row row your boat, gently down the stream, merrily merrily merrily life is but a dream.</p>
</div>
<p style="clear:both;">Notice how the text wraps right around the box every so nicely?</p>
<h2>Problem Floats</h2>
<p>But what happens when the floated box is taller than the non-floated element?</p>
<div style="border: 1px solid black; width: 30em">
<p style="float: left; width: 15em; background-color:#ddd ">I&#8217;m tall and floated left. Row row row your boat, gently down the stream. Row row row your boat, gently down the stream. Row row row your boat, gently down the stream (now doesn&#8217;t that make more sense than Lorem ispum in a post about floats?)</p>
<p style="background-color:#bbb">I&#8217;m not floated</p>
</div>
<p style="clear:both;">And normally that pooches out the bottom and would even overrun this text here, except that <strong>this paragraph has <code>clear:both</code></strong>. I could clear the tall grey paragraph and be done. That&#8217;s the normal, old fashioned way to do things. It works, but it&#8217;s inelegant and sometimes it doesn&#8217;t actually work that well. For example, here&#8217;s the problem that got me digging around again. If this looks right, you&#8217;re not using IE. You can see some funkiness in IE7, and even more in IE6 if I recall right. Here&#8217;s how it looks in your browser and a screenshot of how it looks in IE7:</p>
<div style="background-color: #99FFFF; border: 1px solid black; width: 30em">
<div style="background-color: #FFFFFF; margin:5px; border:1px dashed #30C">
<p style="float: left; width: 15em; background-color:#ddd; border:1px solid black"><strong>This version is rendered by your browser</strong>. I&#8217;m tall and floated left. Row row row your boat, gently down the stream. Row row row your boat, gently down the stream. Row row row your boat, gently down the stream (now doesn&#8217;t that make more sense than Lorem ispum in a post about floats?)</p>
<p style="background-color:#bbb; border:1px solid black">I&#8217;m not floated. I&#8217;m not floated. I&#8217;m not floated. I&#8217;m not floated. </p>
<p style="clear:both;; border:1px solid black">I&#8217;ve got <code>clear:both</code> set. Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum </p>
</div>
</div>
<p><strong>And the screenshot:</strong></p>
<div id="attachment_48" class="wp-caption alignnone" style="width: 501px"><img src="http://raisedbyturtles.org/wp-content/uploads/ie7-float-problem.png" alt="Floated paragraph doesn&#039;t respect padding." title="ie7-float-problem" width="491" height="312" class="size-full wp-image-48" /><p class="wp-caption-text">Floated paragraph doesn't respect padding.</p></div>
<h2>Alternative Float Solutions</h2>
<p>Sometimes, though, that&#8217;s an annoying solution and doesn&#8217;t really work. There are all kinds of hacks and what-not ranging from <a href="http://www.shauninman.com/archive/2006/05/22/clearance_position_inline_absolute">Shaun Inman&#8217;s absolute position and javascript solution</a> to the <a href="http://www.positioniseverything.net/easyclearing.html">clearfix:after solution</a>. It&#8217;s giving me a headache, and the latter doesn&#8217;t work in the particular problem I encountered today where the containing element had a border, so forcing a clear is a problem and the Inman solution would work, but I really just didn&#8217;t want to add the javascript to the WordPress theme I was fixing up (by the way, aside from that problem, it&#8217;s a nice theme called gardenz).</p>
<h2>The Smarter, Better Way to Float</h2>
<p>So then I stumbled on the slickest way to handle this. It&#8217;s an old method, but I had not seen it until recently and I just had to write it here not because it&#8217;s news, but so I wouldn&#8217;t forget it. It is described much better in the articles I mention in the credits, so if this doesn&#8217;t make sense in my disorganized sort of way, go there. Anyway, here it is: <code>overflow: hidden</code> a technique that dates back to at least 2005 and which, furthermore, appears to be based not on some hack, but on actually writing CSS the way the spec intended. The <a href="http://www.w3.org/TR/CSS21/visudet.html#root-height">spec on height and &#8216;auto</a>&#8216; (overflow being an attribute that effect height) states quite directly:</p>
<blockquote><p>
In addition, if the element has any floating descendants whose bottom margin edge is below the bottom, then the height is increased to include those edges.
</p></blockquote>
<p>That comes from a comment by <a href="http://annevankesteren.nl/">Anne</a> on the <a href="http://www.456bereastreet.com/archive/200502/simple_clearing_of_floats/">post over at 456 Berea</a>. It&#8217;s so simple. You just apply this to the element that contains the floated element:</p>
<p>  <strong><code><br />
  .floatedElement {overflow:hidden;<br />
  height:1%;}<br />
  </code></strong> </p>
<p>Halleluja! Praise the Lord as only someone who has wasted countless hours on stupid float problems can praise something quite that geeky. Basically, it&#8217;s this simple, to take the example above.  </p>
<p>A couple of notes: the reason <strong>overflow is <em>hidden</em></strong> is so that you <strong>don&#8217;t get scroll bars in IE/Mac </strong>which otherwise adds scroll bars whether there is any overflow or not. You need to <strong>set a height or a width to get it to work in IE and Opera</strong>. I&#8217;ve opted to set a height, since a percentage height is meaningless in most circumstances and doesn&#8217;t affect the rest of the layout. It&#8217;s probably more robust across browsers if you set a width of 100%, but this creates a problem if you are using a standard box model and you have margins, padding and borders. </p>
<div style="border: 1px solid black; width: 30em; overflow:hidden; height:1%">
<p style="float: left; width: 15em; background-color:#ddd ">I&#8217;m tall and floated left. Row row row your boat, gently down the stream. Row row row your boat, gently down the stream. Row row row your boat, gently down the stream (now doesn&#8217;t that make more sense than Lorem ispum in a post about floats?)</p>
<p style="background-color:#bbb">I&#8217;m not floated.</p>
</div>
<p>And now <strong>this paragraph is not cleared</strong>, but it&#8217;s still safe! Hopefully anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://raisedbyturtles.org/smarter-css-floats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

