I have a table that shall be dynamic (which means I cannot use table-layout: fixed) but that shall have several fixed-width columns in it. The fixed-width columns shall also support colspans of larger than 1.
The dynamic columns (and the table itself) should work just like normal table cells in pure HTML:
- Data shall never get cut off, even when the viewport is too small
- When the table does not fit the viewport, it shall be wider than the viewport
The fixed-width colums should work like this:
- Always have a fixed width
- Cut off any data that does not fit into it
I tried three approaches, none of them works:
- Defining the widths in the first table row
- Defining the widths in a colgroup/col section of the table
- Inserting a
<div>into the fixed-width cells
Nothing works.
table {
border-collapse: collapse;
}
td {
border: 3px solid red;
}
.fw {
overflow: hidden;
height: 20px;
}
<table width="100%">
<colgroup>
<col width="100%">
<col width="50px">
<col width="50px">
</colgroup>
<tr>
<td>My dynamic cell shall be greedy and take up all available space</td>
<td class=fw nowrap>
<div class=fw>My first fixed-width cell shall be of fixed width</div>
</td>
<td class=fw>..</td>
</tr>
<tr>
<td>dynamic</td>
<td class=fw colspan=2>Fixed cells shall also support multiple colspans</td>
</tr>
</table>
As I said, I cannot use table-layout: fixed because I also have dynamic columns.
table-layout: fixed? 2 columns are fixed at 100px each and the second row includes a colspan that is 200px. The fluid column resizes fine.min-widthon the table itself?