title: Why does overflow hidden stop floating elements escaping their container?
body: <p>A common problem that I have with web pages is floating <code>div</code> tags creeping outside of their containers, like shown in the snippet.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#wrapper {
    border: 1px solid red;
  }
  
  #wrapper div {
    float: left;
    font-size: 3em;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="wrapper"&gt;
    &lt;div&gt;Hello World&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>There are a lot of dirty ways to fix this (i.e., inserting a <code>div</code> with <code>clear:both</code>)</p>
  <p>However, a much neater solution I have seen is setting the wrapper <code>div</code> with <code>overflow</code> set to <code>hidden</code>:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#wrapper {
    border: 1px solid red;
    overflow: hidden;
  }
  
  #wrapper div {
    float: left;
    font-size: 3em;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="wrapper"&gt;
    &lt;div&gt;Hello World&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>This works well across browsers, nice and cleanly with no additional markup. I am happy, but I have no idea <strong>WHY</strong> it works this way?</p>
  <p>All the documentation, I had looked at, indicates <code>overflow:hidden</code> is for hiding content, not resizing a parent to fit its children...</p>
  <p>Can anybody offer a explanation for this behavior?</p>
  <p>Thanks</p>
  <p>Original snippets:
  Live example 1: <a href="http://jsfiddle.net/ugUVa/1/" rel="nofollow noreferrer">http://jsfiddle.net/ugUVa/1/</a>
  Live example 2: <a href="http://jsfiddle.net/ugUVa/2/" rel="nofollow noreferrer">http://jsfiddle.net/ugUVa/2/</a></p>