tags:

views:

208

answers:

2
<!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" >
<head>


    <style type="text/css">


    html, body, form, table, tbody, tr {
        height: 100%;
        width: 100%;
        margin: 0px;
        padding: 0px;
        border-style: none;
    }

    tr#MainTitle
    {
        height: 70px;
    }

    div#test {
        height: 100%;
        background-color: blue;
    }

    /* If I remove the 100% here then the scrollbars are removed  and the cell still fills the window but the div no longer fills the cell. */

    td.MainMenu {
        background-color: red;
        height: 100%;
    }
</style>
</head>
<body>
<form name="form1" method="post" action="#" id="form1">
  <table id="Main"> 
    <tbody>

        <tr id="MainTitle">
            <td>Title</td>
        </tr>       

        <tr id="MainMenuRow">
            <td valign="top" class='MainMenu' id='MainMenu'><div id="test">Test</div></td>     
        </tr>
    </tbody>
  </table>
</form>
</body>
</html>

(edit) I've tried to simplify the issue. I have a table. I want the top title row to be fixed in size and the next content row to fill the remaining screen.

As I have it set up if the content cell is height:100% Then the page is larger than the window (by the size of the title row) yet if I switch this to auto the cell is the right size for the window but the contained div does not fill the cell.

Whats going on?

A: 

The problem is being caused by the default margins on the BODY element in your code. You are specifying that the BODY should take up 100% of the available space, but by default, the BODY tag will add a margin to this, causing your elements to take up slightly more than 100% of the available screen space.

You can fix this by adding the following to your BODY style:

html, body, form {
    height: 100%;
    margin: 0px;
}
Ryan Brunner
Unfortunately this isn't the issue. The scrolling area is much larger and seems to be the size of the title row at the top.
haymansfield
What browser are you using? In Firefox this fixes the issue. IE has odd ways of dealing with box models, so you may be seeing different behaviour if you're using that.
Ryan Brunner
It's simple what's going on: #MainTitle + td.MainMenu = 100% + 70px height that add at bottom.
easwee
I'm using ie8 but I just tested it in Firefox and its still there.
haymansfield
+1  A: 

tr does not accept height attribute. You need to set that on td or th element. This code should do the work.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <style type="text/css">
    html, body, form, table {height: 100%;width: 100%;margin: 0px;padding: 0px;border:0;}
    tr th {height:70px;}
    tr td {background-color: blue;position:relative;vertical-align:top;}
    .text {position:relative;height:100%;width:100%;background:yellow;}
</style>
</head>
<body>
<form name="form1" method="post" action="#" id="form1">
  <table id="Main" cellpadding="0" cellspacing="0"> 
        <tr>
            <th>Title</th>
        </tr>       
        <tr>
            <td><div class="text">Test</div></td>     
        </tr>
  </table>
</form>
</body>
</html>
easwee
This does give the correct table layout but the containing div where you have 'Test' would not be able to fill the cell as its height would degrade to auto as its parent element has no assigned height.
haymansfield
I edited the answer - i thought you don't need the inside div. Check it now - the inside div fits nicely.
easwee
Unfortunately this only works in quirks mode. If you add the doctype to move to standards it no longer works.
haymansfield
Damn, forgot about dtd - was writing in notepad. Now this seems like an interesting thing to fix.
easwee