tags:

views:

33

answers:

4

Is there a way Firefox keeps the row height, so if data doesn't fill all the body heigth it keeps an empty space below last row? IE behaves this way, so all rows stay on the top.

I want to code a scroll table with fixed header; sometimes there's not sufficient data on table content to fill the fixed table height.

A sample code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
<head>
<link rel="stylesheet" href="reset.css"/>
<style type="text/css">
    *    {margin:0}
    table {
        border: solid #66CC99;
        border-width: 0px 1px 1px 0px;
        width: 400px;
    }
    th, td {
        border: solid #66CC99;
        border-width: 1px 0px 0px 1px;
        padding: 4px;
    }
    th {
        background-color: #339999;
        color: #FFFFFF;
    }
    tr.alt td {
        background-color: #EEEEEE;
    }
    tbody {
        height: 200px;
        overflow-y: auto;
        overflow-x: hidden;
    }
</style>
<!--[if IE]>
    <style type="text/css">
        div {
            position: relative;
            height: 200px;
            width: 416px;
            overflow-y: scroll;
            overflow-x: hidden;
            border: solid #66CC99;
            border-width: 0px 0px 1px 0px;
        }
        table {
            border-width: 1px 1px 0px 0px;
        }
        thead tr {
            position: absolute;
            top: expression(this.offsetParent.scrollTop);
        }
        tbody {
            height: auto;
        }
        table tbody tr:first-child td {
            padding: 29px 4px 4px 4px;
        }
    </style>
<![endif]-->










    </head><body>

        <table class="treeTable" id="table" cellpadding="0" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th id="col1" class="text" style="width: 100%;" nowrap="nowrap">NAME</th>
                    <th class="selectable" style="width: 14em;" id="th-122002" nowrap="nowrap">12/2002</th>
                    <th class="selectable" style="width: 14em;" id="th-122007" nowrap="nowrap">12/2007</th>
                    <th class="selectable" style="width: 14em;" id="th-072010" nowrap="nowrap">07/2010</th>
                </tr>
            </thead>
            <tbody id="tbody">
                <tr>
                    <td>
                        Name
                    </td>
                    <td>
                        123
                    </td>
                    <td>
                        123
                    </td>
                    <td>
                        123
                    </td>
                </tr>
                <tr>
                    <td>
                        Name
                    </td>
                    <td>
                        123
                    </td>
                    <td>
                        123
                    </td>
                    <td>
                        123
                    </td>
                </tr>
            </tbody>
        </table>

</body></html>
A: 

Did you specify the height attribute, set it to desired value and then see.

Sarfraz
Hi Sac, I've tried to do this way, but it doesn't seem to get the empty space below last row. If you test the sample code, when having that two rows, I cann't get the expected result. It seems that Firefox "forces" to fill the tbody fixed height.
Esteve Camps
@Camps: Seems to be padding issue then due to difference in box model implementation of the two browsers, try putting famous eric meyers reset css on top of your script: http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/
Sarfraz
@sAc, sample code already has reset.css
Esteve Camps
A: 

Hi Esteve,

Can you possibly paste your code? I'd also recommend using a reset.css to remove any prejudice different browsers have interpreting your code.

Adam Beizsley-Pycroft
Adam, I've added some sample code. As you could see, I already coded reset.css. Thanks.
Esteve Camps
Esteve - Which version of IE and which reset.css are you using?
Adam Beizsley-Pycroft
IE7 and reset.css from eric meyer's website (http://meyerweb.com/eric/tools/css/reset/). The problem is on FF.
Esteve Camps
A: 

You can set '&nbsp' as a data if there is no value or you can do is set style attribute to your 'td' tag as <td style="height: 15px;"> </td>

Jprogyog
+1  A: 

One solution that works to a certain extent but doesn't seem perfect is to add this as the last row:

<tr style="height: 100%;"></tr>

It seems to create an empty row that is the size of the area meaning that you can scroll off the bottom til there is only white space which probably isn't ideal. You might be able to play with this a bit (possibly do some rough calculations to work out a sensible height based on how many rows you have) to get a working solution.

Chris
This is the only solution I found for the time being although, as you point out, it is not a perfect solution.
Esteve Camps