html - 使用 Thymeleaf 设置表格中的列宽
问题描述
我有一个表格,其中第一列的宽度是固定的,其余列的宽度将平均占用剩余的速度。问题是列是使用生成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>
推荐阅读
- javascript - 带有 flexbox-wrap 的响应式导航
- python - 绘制具有恒定条形宽度但具有不同 bin 大小的直方图
- javascript - DOM 元素 - Youtube 视频
- flutter - SnackBar 持续时间参数未定义
- nginx - 使用 nginx 出错时重定向到不同的上游
- python - 如何将列表中的元组列表转换为一维数组?
- c - 动态数组重新分配
- python - response.xpath().extract_first() 方法的问题
- java - How do I get the character before a specific character with regex?
- haskell - LiquidHaskell 在“Data.String”类型上运行良好但在“Data.Text”类型上运行良好的简单案例