tags:

views:

281

answers:

1

I'm sorry if this was already answered, but it's kind of difficult to search for something with "100% height".

My problem is that I need 100% height table layout because of automatic cell resizing done by browser, which I don't want to script myself for obvious reasons.

It differs from other "100% problems", in that I need some cells to stick on the top and some on the bottom, and have the middle resized by browser to fill remaining space.

That sort of works, the problem happens when I need that middle part to contain overflowing stuff, and obviously I want overflow:auto there to enable user thru that stuff. It works in WebKit; in Firefox, it doesn't; others not tested. Here's the test case.

<html>
<head>
    <style>

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

        table {
            height: 100%;
            width: 200px;
            border: 0;
        }

        .fill {
            background-color: red;
        }

        .cont {
            overflow: auto;
            height: 100%;
        }

    </style>

</head>
<body>
    <table>
        <tr>
            <td style="height:50px"></td>
        </tr>
        <tr>
            <td style="height:100px"></td>
        </tr>
        <tr>
            <td class="fill">
                <div class="cont">
                    An opaque handle to a native JavaScript object. A JavaScriptObject cannot be created directly. JavaScriptObject should be declared as the return type of a JSNI method that returns native (non-Java) objects. A JavaScriptObject passed back into JSNI from Java becomes the original object, and can be accessed in JavaScript as expected
                </div>
            </td>
        </tr>
        <tr>
            <td style="height:100px"></td>
        </tr>
    </table>
</body>

+3  A: 

Try this it works!

I tested it using

  • Internet Explorer 7 & 8 (Windows)
  • FireFox 3.5 (Mac & Windows)
  • Safari 4.0 (Mac & Windows)

Maybe you want to change the width and increase the min-height to a pixel value.

Demo Source

<html>
<head>
    <style>

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

        table {
            height: 100%;
            width: 200px;
            border: 0;
        }

        .fill {
            background-color: red;
        }

        .cont {
            position:relative;
            max-height:100%;
            min-height:100%;
            height: 100%;
        }

        .cont2 {
            position:absolute;
            height: 100%;
            overflow:auto;
        }

    </style>

</head>
<body>
    <table>
        <tr style="height:50px">
            <td style="height:50px">50px</td>
        </tr>
        <tr style="height:50px">
            <td style="height:100px">100px</td>
        </tr>
        <tr>
            <td class="fill">
                 <div class="cont">
                    <div class="cont2">
                    An opaque handle to a native JavaScript object. A JavaScriptObject cannot be created directly. JavaScriptObject should be declared as the return type of a JSNI method that returns native (non-Java) objects. A JavaScriptObject passed back into JSNI from Java becomes the original object, and can be accessed in JavaScript as expected
                    </div>
                 </div>
            </td>
        </tr>
        <tr style="height:50px">
            <td style="height:100px">100px</td>
        </tr>
    </table>
</body>
Ghommey
Awesome, thank you very much! Now, it seems that you can also answer, how can I make it done with variable height cells on top/bottom? In other words, I don't know their height, but I can measure them, which is tricky and I would like to avoid that
skrat
Set there height to 1px `height: 1px;`. This might work. Just play with height and min-height.
Ghommey
Sounds good, that should work, just testing with Strict doctype, and it seems not to work anymore :(
skrat
I can set up new question and bounty again if that can help somehow :)
skrat