tags:

views:

43

answers:

1

I am trying to style the divs to fill the entire contents of the table cell. That means that the background color should fill the height of the table cell. How can I get the div to fill the height of the table cell?

<style>
    body { background-color: #ccc; }
    table, tr, td { border: 2px solid #00f; }
    td > div { background-color: #fff; color: #f00; padding: 5px;}
</style>

<table>
    <tr>
        <td>
            <div style="position: relative; z-index: 1000">
                line<br />line<br />line
            </div>
        </td>
        <td>
            <div style="position: relative; z-index: 1000">fill contents</div>
        </td>
    </tr>
</table>

The background color should fill the height of the "fill contents" table cell:

alt text

Here is a jsfiddle to play with.

Also, the reason I am asking this is because I can't style the td tag due to a workaround in my JavaScript.

Update: This may help to visualize my specific problem: http://jsfiddle.net/pjd6x/8/ There is an overlay that is appearing on top of the table (intentionally) and below the divs (also intentional), but I would like the divs to be the same height (to look as if they are filling the contents of the tds).

+1  A: 

If your elements can have a fixed height:

td > div {
    background-color:#FFFFFF;
    color:#FF0000;
    padding:5px;
    display:table-cell;
    height:80px;
    vertical-align:middle;
}
gearsdigital
that may be what I have to do (specify a fixed height)...however, I can't use `display:table-cell` since that's part of the problem that I am avoiding, which means I can't use `vertical-align:middle` but I would still like to align the text in the middle...hmmm...not sure what I should do
Andrew
You could try to explain what problem you are try to avoiding. Maybe this specific problem is only a symptom of anything bigger...
gearsdigital
Btw... whats about a background-color for the table?! Can't imagine that it won't work o_O
gearsdigital