title: How can I center using percentages?
body: <p>As an experiment, I've been trying to center a DIV in a BODY tag using percentages in CSS.  I think I had it figured out at one point, but thanks to the magic of TopStyle not having a history once you save, I lost it.</p>
  
  <p>So, here is my HTML:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;link href="shadow.css" rel="stylesheet" type="text/css" /&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="box"&gt;&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And, here is my CSS:</p>
  
  <pre><code>*
  {
      margin: 0;
      padding: 0;
  }
  
  body
  {
      background-color: #EEEEEE;
      margin: 10%;
  }
  
  div#box
  {
      position: absolute;
      background-color: #FFFFFF;
      width: 740px;
      min-width: 80%;
      min-height: 80%;
      border: #CCCCCC thin solid;
  }
  </code></pre>
  
  <p>To answer your immediate questions:</p>
  
  <p><strong>Why am I using absolute positioning on the box?</strong><br />
  So that the box will accept 80% as it's height even without content to stretch it.</p>
  
  <p><strong>Why am I width, min-width and min-height like this?</strong><br />
  Since I want the box DIV to take up 80% of the available space, it made sense to use minimums. I'm using a pixel width to make sure that no matter how small the area gets, it won't go any thinner than 740px, causing the browser to activate the horizontal scroll bar.  In theory, they content height should activate the vertical scroll bar if the content pushes passed 80% of the available area.</p>
  
  <p>Now the trick is to get it dead centered and maintain a 10% space around the box.  I've tried applying "margin: 10%;" to BODY, then "padding: 10%;" to BODY, and finally "margin: 10%" to the box DIV.  All of those choices gives me the same result: it's centered horizontally but is acting strange vertically.  I'm not getting even space on all sides.  The only thing that is behaving as wanted is that the box DIV does appear to be using 80% of the available space.</p>
  
  <p>It seems like this should be right.  The box DIV is taking up 80%, the margins are taking up 10% on each side (20% vertically and 20% horizontally), making 100%.  Not sure why it's not working.</p>
  
  <p>I swear I had this working in a similar manner, and now I've lost it.</p>
  
  <p>Does anyone have an explanation as to why the percentages don't seem to be displaying correctly and what solution I would need?</p>
  
  <p>Thanks!</p>