I have a scenario which requires a complex layout within table header <th>
elements. I want to approach the problem by making the <th>
elements a flex container.
However, if I start with this minimal example
and change the <th>
elements to display: inline-flex
, the table becomes:
I.e., the column width of the header no longer matches the column width of the <td>
elements.
How can I make use of flexbox inside the header without messing up column rendering?
Edit to clarify the use case: My <th>
elements will eventually contain multiple elements, with left+right alignment (similar to this question). In addition I want to be able to control the stretch behavior (that's why flexbox instead of just floats).
Example jsfiddle:
<table>
<thead>
<tr>
<th class="column-header">A</th>
<th class="column-header">B</th>
<th class="column-header">C</th>
</tr>
</thead>
<tbody>
<tr>
<td>Something</td>
<td>Something</td>
<td>Something</td>
</tr>
</tbody>
</table>
table, th, td {
border: 1px solid #000;
}
.column-header {
display: inline-flex;
}