Brizio
Brizio

Reputation: 31

100% height div inside 100% td

Ok, so here is my problem.. and its buggin me for a while...  i need to set the following DIV 100% height inside this TD without any side-effects (by that i mean scrolling), because for some unknown reason, when i set it to 100% height, looks like IE 8 does some wrong calculations.. I tried a lot of combinations but no success.. transitional doctype is required... thanks in advance for any help!

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<style>
html, body
{
    height:100%;
    margin:0px;
    padding:0px;
}
</style>
<head>
    <body>
        <table style="height:100%" border="1">
            <tr>
                <td>TOP</td>
            </tr>
            <tr style="height:100%">
                <td style="height:100%">
                    <div style="border:1px dotted blue; height:100%">CONTENT</div>
                </td>
            </tr>
        </table>
    </body>
</html>

Upvotes: 1

Views: 2648

Answers (2)

Damien-Wright
Damien-Wright

Reputation: 7544

The border on the div is 'external' to the height... So really, the style you are applying is a height of 100% + 2px (1px top border, 1px bottom border)...

If you remove the border the true height will be 100% and the scroll bar should disappear :)

As commented below, the height:100% in the bottom cell makes the total table height = first row height + the 100% of the bottom row height.


UPDATE: okay, so its not pretty, but its the best i've got:

if you were to give the div an id of blah and use the following jquery to hack the height of the div to that of it's parents... this does require a height definition for the first row/cell though.. i set at 100px for an example.

$('#blah').height($('#blah').parent().height());

jsfiddle example... http://jsfiddle.net/Damien_at_SF/vwcvN/

Upvotes: 1

0x434D53
0x434D53

Reputation: 1463

You should have a look at the foundations of the css box models. For example: http://www.w3.org/TR/CSS21/box.html

Upvotes: 0

Related Questions