• Home
  • Blog
  • Demos
  • About
  • ------------------
  • Articles
  • Csharp(59)
    • controls (4)
    • methods (5)
    • tutorials (50)
  • Html(1)
    • tutorials (1)
  • Java(10)
    • mobile (10)
  • Javascript(5)
    • tutorials (5)
  • Linux(3)
    • tutorial (3)
  • Math(10)
    • tutorials (10)
  • Php(15)
    • functions (1)
    • mysql (6)
    • tutorials (8)
  • Sql(23)
    • tutorials (23)
  • Vba(1)
    • tutorials (1)

100 percent div height

Written: 2010-02-05 06:55:54
Mood: Stupid
Subject: programming
So, I had this problem just now where I had three divs, one #wrap (a container div), a #sidebar and a #main div. Now, the #sidebar div is obviously a sidebar (that in this case resides to the left), the #main div is the right, main, part of the page where the content shows and they are both encapsulated by the wrapper, like this:

<div id="wrap">
<div id="sidebar">
//my sidebar
</div>
<div id="main">
//my content
</div>
</div>


The problem I had was that if the sidebar and content part was shorter than the viewport (browser window) then the page would stop half-way down. Using Faux columns this made the page look very odd and I had no intention to use a footer (which would still look odd), so I decided that I would use the min-height css property. Problem is, IE6 doesn't support it, so out I threw it.
I then decided that it would be a great idea to give the #wrap div 100% height, like this:

#wrap{
height: 100%;
}


This, however, did very little to help me, until I found this forum thread that touched the subject and helped me out.
The problem is that the #wrap now has a 100% height in relation to nothing which automagically sets it to height:auto, and that's not good, so what you have to do is this:

body{
height: 100%;
}
#wrap{
height: 100%;
}


Ah! There we go, now the body is 100% which means that the wrapper is set to 100% of the body. Sweet!

I am content now.