![](/img/trans.png)
[英]HTML table with fixed header and footer and scrollable body without fixed widths
[英]How to set HTML table column widths as a percentage (without table footer affecting table body)?
我真的很难理解如何在 HTML 表格中设置列宽的样式。 我无法tfoot
为什么不应用百分比宽度以及为什么tfoot
内的列会影响 tbody 中的列宽。
任何人都可以对此有所了解,也许可以解释我如何将tbody
的列设置为三分之一 (33.333%) 并将tfoot
列设置为二分之一 (50%) 并实际跨越整个宽度表(现在它们只跨越上面的 2 列,而不是 3 列)?
任何帮助/指导将不胜感激。
tbody, tfoot { width: 100%; } tbody tr td { width: 33.333%; } tfoot tr th, tfoot tr td { width: 50%; }
<table border="1"> <tbody> <tr> <td>Body Row 1 Column 1</td> <td>Body Row 1 Column 2</td> <td>Body Row 1 Column 3</td> </tr> </tbody> <tfoot> <tr> <th>Footer Row 1 Column 1</th> <td>Footer Row 1 Column 2</td> </tr> <tr> <th>Footer Row 2 Column 1</th> <td>Footer Row 2 Column 2</td> </tr> <tr> <th>Footer Row 3 Column 1</th> <td>Footer Row 3 Column 2</td> </tr> </tfoot> </table>
如果您不受限制以至于必须使用一张桌子,为什么不只使用一张桌子呢?
<tfoot>
<tr>
<td colspan="3">
<table>
<tbody>
<tr>
<td>First half</td>
<td>Second half</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tfoot>
只需确保样式也适用,并为您的table table { width: 100%; }
table table { width: 100%; }
,无边框、边距、填充等。
我发现最好的解决方案是那些你忽略问题的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.