Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill 100% of an absolutely positioned div? (IE7+) [duplicate]

Possible Duplicate:
CSS height 100% in IE7

I'd like to have a centered block on a webpage that's filled to 100% by a child div.

Here is my HTML code:

<div id="parent">
    <div id="child"></div>
</div>

Here is my CSS:

#parent {
   position: absolute;
   background-color: blue;
   top: 2em;
   left: 4em;
   bottom: 3em;
   right: 2em;  
}

#child {
   position: relative;
   background-color: red;
   height: 100%;   
}

And here is a JSfiddle: http://jsfiddle.net/XMS2G/1/

The problem is that in Internet Explorer 7, the browser does not cause the child div to expand to the entire parent div. How would I accomplish this without using Javascript?

like image 232
mpark Avatar asked Nov 13 '12 19:11

mpark


3 Answers

Consider using position:absolute for child as well. And then just use top:0px; bottom:0px; right:0px; left:0px;

I think it will work.

like image 98
tonino.j Avatar answered Sep 21 '22 00:09

tonino.j


You need to give the child position: absolute and set left, right, top, bottom to 0.

See it in action.

like image 43
Jon Avatar answered Sep 18 '22 00:09

Jon


You'll likely have to set a hard-coded width for the parent DIV to get IE7 to behave nicely. the centering can be done with the "margin-left: auto;" "margin-right: auto;" css.

like image 32
Louis Ricci Avatar answered Sep 19 '22 00:09

Louis Ricci