Jimmy Tschonga
Jimmy Tschonga

Reputation: 57

Div height 100% within div

I got the followin code, which doesn't do the trick:

<div id="wrap">
    <div class="navigation">    
        <ul>      
            <li>
            </li>
        </ul>
     </div>


     <div id="main">
       Content
     </div>
</div>

I want the wrap to be 100% height. This works just fine. But as soon as i try the #main div to be 100% heights as well, it doesn't. This div always collapses to the height of content.

html{height:100%;}
body{overflow-y:scroll; margin:0px; padding:0px; height:100%;}
#wrap{
    min-height: 100%; /* Mindesthöhe für moderne Browser */
    height:auto !important; /* Important Regel für moderne Browser */ 
    height:100%; /* Mindesthöhe für den IE */ 
    width:100%;
    position:absolute;
    overflow:hidden;
}


#main{
    width: 980px !important;


    height:100%; /* IE6: treaded as min-height*/
    min-height:100%; /* real browsers */
    height:auto !important;


}

Can somebody please help me solve this problem? Thanks in Advance

Upvotes: 0

Views: 23802

Answers (2)

showdev
showdev

Reputation: 29188

In your case, it doesn't seem that the #main div necessarily needs to expand to 100%. What needs to expand is the red background.

I suggest using a "faux background". Using position:fixed, you can add a red background that will not scroll with the page. The rest of the content can scroll over it. Something like this.

html,
body {
  margin: 0px;
  padding: 0px;
  width: 100%;
  height: 100%;
}

div#background {
  position: fixed;
  width: 100%;
  height: 100%;
}

div#background div#color {
  position: relative;
  background-color: red;
  width: 980px;
  height: 100%;
  margin: 0px auto;
}

div#nav {
  position: relative;
  background-color: #FFF;
}

div#main {
  position: relative;
  width: 950px;
  margin: 0px auto;
}
<div id="background">
  <div id="color"></div>
</div>

<div id="nav">NAVIGATION<br />even two lines<br /> or more</div>

<div id="main">
  <p>CONTENT GOES HERE</p>
</div>

Upvotes: 1

ATOzTOA
ATOzTOA

Reputation: 36000

Change the style for wrap. Live Demo

#wrap {
    min-height: 100%; /* Minimum height for modern browsers */
    height:100%; /* Minimum height for IE */ 
    width:100%;
    position:absolute;
    overflow:hidden;
    border:1px solid blue;
}

Upvotes: 5

Related Questions