使用thyymleaf在表中设置列宽度



我有一个表,其中第一列将具有固定的宽度,其余列的宽度将相等地占用剩余的空间。问题是这些列是使用th:each生成的,列的数量会有所不同。

如何将第一列设置为固定宽度,并将剩余空间平均分配给未知数量的列?

<thead>
<tr>
<th style="width: 25%">
Fixed width
</th>
<th th:each="instance: ${headers}">
Dynamic width
</th>   
</tr>
</thead>

你可以这样计算宽度:

<thead th:with="fixed_width=25, dynamic_width=${(100 - fixed_width) / (#lists.size(headers) - 1)}">
<tr>
<th th:each="instance, status: ${headers}" th:style="|width: ${status.first ? fixed_width : dynamic_width}%|">
Dynamic width
</th>   
</tr>
</thead>