I have an arbitrary number of tables whose heights I do not know in advance.
An outer table, and several inner tables contained like so within the outer table
<tr><td><table></table></td></tr>
The problem is that if one of the tables is larger than the others the remaining tables will not stretch to fill any gap above and below created by the larger table.
<!DOCTYPE html>
<html lang="en">
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
padding: 0;
margin: 0;
}
th,
td {
width: 14ch;
height: 1ch;
}
</style>
<head>
<meta charset="UTF-8">
<title>Wont Stretch</title>
</head>
<body>
<table id="outer">
<tr>
<th style="width: 1ch"></th>
<th style="width: 14ch">1</th>
<th style="width: 1ch"></th>
<tr>
<td style="width: 1ch">
<table>
<tr>
<td>T1</td>
</tr>
<tr>
<td>T1</td>
</tr>
</table>
</td>
<td>
<table id="col1">
<tr>
<td>test2</td>
</tr>
<tr>
<td>test2</td>
</tr>
<tr>
<td>test2</td>
</tr>
<tr>
<td>test2</td>
</tr>
</table>
</td>
<td style="width: 1ch">
<table>
<tr>
<td>T3</td>
</tr>
<tr>
<td>T3</td>
</tr>
</table>
</td>
</tr>
</tr>
</table>
</body>
I have tried rowspan
and table-layout: fixed
, both of which did nothing, but the only solution that came close was setting the height ahead of time which I cannot do as I don’t know in advance what the largest table will be. Even then there was a gap I could not fill, it was merely close enough for nukes and hand grenades.
2
Answers
Is there a reason why you want to use nested tables? If I understand the question correctly you can achieve this by using 1 table and for example rowspan/colspan.
As mentioned in an answer that the better solution is to use rowspan and colspan. But if you have to use the nested tables, one of the solution is to write class names to the tables and in CSS, make their height 100%.