I need to have table that has rows with fixed height and that table itself must be of fixed height. For example all rows would be of 8px height and table would be of height 400px. If there would be less rows than total height of table, then remaining part of the table should be like a gap.
But css automatically readjusts row height if I set fixed height on table.
I need table to look like this:
|row |cont |
|row |cont |
|row |cont |
| |
| |
| |
|End of table|
I tried this:
CSS:
.t-table {
border: 1px solid black;
height: 400px;
border-collapse: collapse;
}
td {
border: 1px solid black;
}
HTML:
<table class="t-table">
<tr style="line-height: 8px">
<td>A</td>
<td>B</td>
</tr>
<tr style="line-height: 8px">
<td>1</td>
<td>2</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
Or you can check it here: https://jsfiddle.net/utrwqfux/
P.S. So if I force height on table it will ignore height on rows. Last tr was without height, so the idea was for it to re-size automatically filling empty gap.
I agree with Wart Claes on display divs as table elements vs using old school table layout. But the problem you're running into is that the browser is adding a tbody element into your table. This element is forcing the row height. To fix this there are two ways.
1) Set the tbody to display as block, this will make the browser disregard its display properties and do exactly as you want.
https://jsfiddle.net/benneb10/utrwqfux/1/
2) Set the table height of the table with the tbody:
However, doing this won't make your table 400px as you want. It will force the tr to be exactly 8px though.
https://jsfiddle.net/benneb10/utrwqfux/2/
Basically I did this by creating the table in CSS and not in HTML. This give a bit more control.
HTML:
CSS:
Live example: http://codepen.io/WartClaes/pen/mVxdQg?editors=1100
The only issue here is that the
td
's will be higher then 8px since their content is bigger then that. Is 8px the actual height?https://jsfiddle.net/pf8g49h2/
You can set
height:8px
to the first and secondtr
. And remove the middle border from the empty cells in the lasttr
.