title: css height-related question
body: <p>This is more of a request for an explanation as to help solving a problem... in setting up the layout for a site, I had been setting the background colours of all of my div's so that I could see where each one was being displayed, etc.. just for getting the basic shell setup.</p>
  
  <p>I noticed at one point however that although the content in my footer div displayed in the right spot, the background colour was displaying much higher than it and was displaying behind some boxed content that appears above the footer. The background colour of my 'boxes' div, which contained 3 horizontal boxes, was not displaying at all, and the footer colour was showing where the boxes colour should have. I had always thought that since I hadn't specified a height for boxes, it would stretch to the height of the 3 horizontal boxes which were placed inside it....but apparently this isn't the case. As soon as I set my 'boxes' div to have a height the same as the horizontal boxes, the colour showed up properly and pushed the footer down to the correct place.</p>
  
  <p>Can someone please explain to me why this happens? And why I had to specify the height of 'boxes' in order for the background colour for it to be displayed, and why it didn't just stretch to the height of the horizontal boxes contained within it?</p>
  
  <p>Here are some jsFiddle links to see the differences (I've also include the actual code below as well if useful). Note that the 'boxes' background colour I want to see is black..footer is red.</p>
  
  <p>Without height specified and footer (red) coming up too high: <a href="http://jsfiddle.net/KgFKH/" rel="nofollow">http://jsfiddle.net/KgFKH/</a></p>
  
  <p>With height specified and displaying properly: <a href="http://jsfiddle.net/eD4d7/" rel="nofollow">http://jsfiddle.net/eD4d7/</a></p>
  
  <p>I apologize if its a stupid question, I had just always thought that the container div would stretch to the height of the elements within it...so I am finding this very puzzling!</p>
  
  <p>html:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
       &lt;link href="style.css" rel="stylesheet" type="text/css" media="screen" /&gt; 
  &lt;/head&gt;
  
  
  &lt;body&gt;
  
  
      &lt;div id="header-stretch"&gt;
          &lt;div id="header" class="container"&gt;
              &lt;h2&gt;THIS IS THE HEADER&lt;/h2&gt; 
              &lt;p&gt;nav&lt;br /&gt;will&lt;br /&gt;go&lt;/br &gt;here
          &lt;/div&gt;&lt;!--header--&gt;
      &lt;/div&gt;&lt;!--header stretch--&gt;
  
      &lt;div id="slider-stretch"&gt;
          &lt;div id="slider" class="container"&gt;
              &lt;p&gt;Slider will go here...&lt;/p&gt;
          &lt;/div&gt;&lt;!--slider--&gt;
      &lt;/div&gt;&lt;!--slider stretch --&gt;
  
      &lt;div id="main-stretch"&gt;
          &lt;div id="main" class="container"&gt;
              &lt;p&gt;Main block of content will be in here.&lt;/p&gt;
          &lt;/div&gt;&lt;!--main container--&gt;
      &lt;/div&gt;&lt;!--main stretch--&gt;
  
      &lt;div id="boxes-stretch"&gt;
      &lt;div id="boxes" class="container"&gt;
          &lt;div class="box" id="box1"&gt;
              &lt;h2&gt;Box 1 Heading&lt;/h2&gt;
              &lt;p&gt;Box 1 content here...&lt;/p&gt;
              &lt;p class="c2action"&gt;&lt;a href="#"&gt;learn more&lt;/a&gt;&lt;/p&gt;
          &lt;/div&gt;&lt;!--box1--&gt;
  
          &lt;div class="box" id="box2"&gt;
              &lt;h2&gt;Box 2 Heading&lt;/h2&gt;
              &lt;p&gt;Box 2 &lt;br /&gt;content here...&lt;/p&gt;
              &lt;p class="c2action"&gt;&lt;a href="#"&gt;learn more&lt;/a&gt;&lt;/p&gt;
          &lt;/div&gt;&lt;!--box2--&gt;
  
          &lt;div class="box" id="box3"&gt;
              &lt;h2&gt;Box 3 Heading&lt;/h2&gt;
              &lt;p&gt;Box 3&lt;br /&gt; content &lt;br /&gt;here...&lt;/p&gt;
              &lt;p class="c2action"&gt;&lt;a href="#"&gt;Click here for Map &amp;amp; Directions&lt;/a&gt;&lt;/p&gt;
          &lt;/div&gt;&lt;!--box3--&gt;
      &lt;/div&gt;&lt;!--boxes--&gt;
      &lt;/div&gt;&lt;!--boxes-stretch--&gt;
  
      &lt;div id="footer-stretch"&gt;
          &lt;div id="footer" class="container"&gt;
              &lt;p&gt;&amp;copy; Footer&lt;/p&gt;
          &lt;/div&gt;&lt;!--footer--&gt;
      &lt;/div&gt;&lt;!--footer stretch--&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>css (w/o height declared):</p>
  
  <pre><code>html, body, div, span, applet, object, iframe,  
  h1, h2, h3, h4, h5, h6, p, blockquote, pre,  
  a, abbr, acronym, address, big, cite, code,  
  del, dfn, em, font, img, ins, kbd, q, s, samp,  
  small, strike, strong, sub, sup, tt, var,  
  b, u, i, center,  
  dl, dt, dd, ol, ul, li,  
  fieldset, form, label, legend,  
  table, caption, tbody, tfoot, thead, tr, th, td {  
      margin: 0;  
      padding: 0;  
      border: 0;  
      outline: 0;  
      font-size: 100%;  
      vertical-align: baseline;  
      background: transparent;  
  }  
  
  body {background: #FFFFFF; font-family: Arial, verdana, sans-serif;}
  
  .container {margin: 0 auto; width: 940px;}
  
  #header-stretch{background:#ffff00;}
  
  #header {overflow: hidden; padding-bottom: 10px;}
  
  #header h1 a {
      background: url("images/logo.gif") no-repeat;
      float: left;
      height: 37px;
      width: 191px;
      margin-top: 40px;
      text-indent: -9999px;
  }
  
  #header ul{
      float: right;
      list-style: none;
      margin-top: 50px;
  }
  
  #header ul li{
      float: left;
      margin-left: 10px;
      padding: 10px 0 10px 12px;
  }
  
  #header ul li a {
      text-decoration: none;
      font-size: 17px;
      padding: 10px 0px 10px 2px;
      color:#878686;
  }
  
  #slider-stretch{
      background-color:#9900ff;
  }
  
  #slider{
      background-color:#00FF00;
      height: 260px;
  }
  
  #main-stretch{
      background-color:#3c0303;
      height: 170px;
  }
  
  #main{
      padding:15px 0px;
  }
  
  #main p{
      padding-top:15px;
      color:#FFFFFF;
  }
  
  #boxes-stretch{
      background-color:#0000FF;
  
  }
  
  #boxes{
      margin-top: 20px;
      background-color:#000000;
  
  }
  
  .box{
      position:relative;
      width:296px;
      height:270px;
      float:left;
      background-color:#999999;
  
  }
  
  .box h2{
      font-size: 16px;
      margin-top: 18px;
      margin-left: 24px;
      color: #353535; 
  }
  
  .box img{
      margin-top: 10px;
      margin-left: 24px;
  }
  
  .box p{
      margin-top: 10px;
      margin-left: 24px;
      width: 252px;
      font-size:13px;
      color:#525151;
  }
  
  p.c2action{
      position:absolute;
      bottom:10px;
      text-align:right;
      font-size: 14px;
  }
  
  .c2action a{
      color:#353535;
  }
  
  
  #box1{  
      margin-right: 20px;
  }
  
  #box2{
      margin-right: 20px;
  }
  
  
  #footer-stretch{
      background-color:#ff0000;
  }
  
  #footer{
      padding-top:10px;
      padding-bottom:10px;
      font-size: 11px;
      color:#7e7e7e;
      overflow:hidden;
  }
  
  #footer p {
      text-align: center;
  }
  </code></pre>
  
  <p>css (w/ height declared):</p>
  
  <pre><code>html, body, div, span, applet, object, iframe,  
  h1, h2, h3, h4, h5, h6, p, blockquote, pre,  
  a, abbr, acronym, address, big, cite, code,  
  del, dfn, em, font, img, ins, kbd, q, s, samp,  
  small, strike, strong, sub, sup, tt, var,  
  b, u, i, center,  
  dl, dt, dd, ol, ul, li,  
  fieldset, form, label, legend,  
  table, caption, tbody, tfoot, thead, tr, th, td {  
      margin: 0;  
      padding: 0;  
      border: 0;  
      outline: 0;  
      font-size: 100%;  
      vertical-align: baseline;  
      background: transparent;  
  }  
  
  body {background: #FFFFFF; font-family: Arial, verdana, sans-serif;}
  
  .container {margin: 0 auto; width: 940px;}
  
  #header-stretch{background:#ffff00;}
  
  #header {overflow: hidden; padding-bottom: 10px;}
  
  #header h1 a {
      background: url("images/logo.gif") no-repeat;
      float: left;
      height: 37px;
      width: 191px;
      margin-top: 40px;
      text-indent: -9999px;
  }
  
  #header ul{
      float: right;
      list-style: none;
      margin-top: 50px;
  }
  
  #header ul li{
      float: left;
      margin-left: 10px;
      padding: 10px 0 10px 12px;
  }
  
  #header ul li a {
      text-decoration: none;
      font-size: 17px;
      padding: 10px 0px 10px 2px;
      color:#878686;
  }
  
  #slider-stretch{
      background-color:#9900ff;
  }
  
  #slider{
      background-color:#00FF00;
      height: 260px;
  }
  
  #main-stretch{
      background-color:#3c0303;
      height: 170px;
  }
  
  #main{
      padding:15px 0px;
  }
  
  #main p{
      padding-top:15px;
      color:#FFFFFF;
  }
  
  #boxes-stretch{
      background-color:#0000FF;
  
  }
  
  #boxes{
      margin-top: 20px;
      background-color:#000000;
      height:270px;
  }
  
  .box{
      position:relative;
      width:296px;
      height:270px;
      float:left;
      background-color:#999999;
  
  }
  
  .box h2{
      font-size: 16px;
      margin-top: 18px;
      margin-left: 24px;
      color: #353535; 
  }
  
  .box img{
      margin-top: 10px;
      margin-left: 24px;
  }
  
  .box p{
      margin-top: 10px;
      margin-left: 24px;
      width: 252px;
      font-size:13px;
      color:#525151;
  }
  
  p.c2action{
      position:absolute;
      bottom:10px;
      text-align:right;
      font-size: 14px;
  }
  
  .c2action a{
      color:#353535;
  }
  
  
  #box1{  
      margin-right: 20px;
  }
  
  #box2{
      margin-right: 20px;
  }
  
  
  #footer-stretch{
      background-color:#ff0000;
  }
  
  #footer{
      padding-top:10px;
      padding-bottom:10px;
      font-size: 11px;
      color:#7e7e7e;
      overflow:hidden;
  }
  
  #footer p {
      text-align: center;
  }
  </code></pre>