NameSilo

XHTML Question: Best way to make div height 100%?

Spaceship Spaceship
Watch

1901gt

VIP Member
Impact
11
Let say, I have this example.

Code:
<div id="container">

<div class="contentA left">Lorem lipsum</div>
<div class="contentB right">Lorem lipsum</div>

</div>

.. where left and right is float left and right respectively.

What is the best method (must be validated) to make the container's height 100% or fluid without declaring a fixed height value?

I seems to have some problem with this whenever there is floats inside the div.

Before, I used to use this:

Code:
#container {
overflow: auto;
height: 100%;
min-height: 100%;
}

But sometimes, the horizontal and vertical scrollbars will appear inside the div, especially in IE7.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Clear the floats. This isn't necessarily the best way to do it, but it works.

Code:
<div id="container">

<div class="contentA left">Lorem lipsum</div>
<div class="contentB right">Lorem lipsum</div>

<div style="clear: both;"> </div>
</div>
 
0
•••
Ok great! Works well for me. :)
 
0
•••
I think I've found a better way. Silly me.
Just insert the following inside the div and it will auto expand.

Code:
#container {
overflow: hidden;
}

:hehe:
 
0
•••
That should work, but if I remember correctly that could cause some of the content in the container to get cut off.
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Appraise.net

We're social

Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back