views:

291

answers:

2

Okay, so I've got a problem - and I'd love to have it fixed.

I am using my favourite way of setting up a simple header/content/footer layout. The problem is that any elements I add to the 'content' div of my layout can not be expanded to 100% in Internet Explorer (as far as I know, IE only). I understand there is no height declared to the 'content' element, but because of the style of its positioning (declaring an absolute top AND bottom), the element fills the desired area. (The content element has a background color defined so you can see that the div is in fact filling between both the header and the footer.)

So my problem is, since the div is clearly expanded between the two, why can't a child be set to 100% to fill that area? If anyone has any solutions, I'd love to hear them. (I'm looking for a solution that won't involve designing by an entire different layout.. or at least perhaps an explanation of why this is happening. I'm assuming at this point it's because of the lack of a height declaration -- but the div is expanded, so I don't get it!)

You can view a page of the example here: http://www.elizabethlouter.com/html/index.html And here is the code as used on the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml"&gt;
    <head>
    <meta name="robots" content="noindex" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>No 100% height on 'content' child div in IE</title>
    </head>
    <style>
    html, body {
     width:100%;
     height:100%;
     margin:0px;
     padding:0px;
    }
    body {
     position:relative;
    }
    #wrapper {
     position:absolute;
     top:0px;
     width:960px;
     height:100%;
     left:50%;
     margin-left:-480px;
    }
     #header{
      position:absolute;
      top:0px;
      left:0px;
      width:100%;
      height:200px;
      background-color:#999;
     }
     #content{
      position:absolute;
      top:100px;
      bottom:50px;
      left:0px;
      width:100%;
      background-color:#F7F7F7;
     }
      #content_1{
       width:200px;
       background-color:black;
       height:100%;
       float:left;
      }
     #footer{
      position:absolute;
      bottom:0px;
      left:0px;
      width:100%;
      height:50px;
      background-color:#999;
     }  
    </style>

    <body>
    <div id="wrapper">
     <div id="header">
        </div>
        <div id="content">
         <div id="content_1">
            </div>
        </div>
        <div id="footer">
        </div>
    </div>
    </body>
    </html>
+2  A: 

Try this:

#content_1{
width:200px;
background-color:black;
height:100%;
position: absolute;
}

IE 7 and below assign a value called "hasLayout" to elements that need positioning. Sometimes to work out little quirks like this you have to force an item to have a layout which in this case means setting its position to absolute.

Peter
Wow - That actually worked!!! On the site I was using this similar code on, the elements were floating, so I didn't think to absolute position them.You are my savior of the month Peter!Many thanks. (Man - I though the hasLayout days were over... guess I was wrong)PS - Is there a simple way to add hasLayout to a the div if it were floating? (just out of curiosity, as it's not necessary for what I need it for).
Jordan Rynard
My goto hasLayout style is always "zoom:1;"
bmoeskau
Glad I could help! If I remember correctly there's several ways to trigger the hasLayout flag without actually changing anything on a div, but since most situations are so unique it would be hard to say exactly what would work if the div were floating. Once you know the name of the problem though its a lot easier to find an answer.
Peter
A: 

I have an already centered website by using the css width: 790px; margin: 0 auto;. When I use this position: absolute; method this would break my method of aligning the website in the middle.

I might have to try the method zoom: 1; instead then. Can anybody confirm if this is actually properly working?

Mr.Mark