gpt4 book ai didi

css - 第一行单元格跨多列时的列宽

转载 作者:行者123 更新时间:2023-11-28 08:38:30 38 4
gpt4 key购买 nike

当第一行中的单元格跨越多列时,如何在具有指定宽度且使用固定表格布局的表格中指定列宽?

使用以下代码,第一列获得所需的宽度 100px。其他 3 列的宽度相等,这不是我想要的。如何让第 2 列的宽度 200px、第 3 列 400px 和第 4 列填充剩余的空间,同时仍然使用 table-layout: fixed?

<table style="width: 100%; table-layout: fixed;">
<tr>
<td style="width: 100px">First cell</td>
<td colspan="3">Spanning cell</td>
</tr>
<tr>
<td style="background: red">1</td>
<td style="width: 200px; background: blue">2</td>
<td style="width: 400px; background: green">3</td>
<td style="background: yellow">4</td>
</tr>
</table>

最佳答案

您可以使用colgroupcol:

<table style="width: 100%; table-layout: fixed;">
<colgroup>
<col style="width: 100px;">
<col style="width: 200px;">
<col style="width: 400px;">
</colgroup>
<tr>
<td>First cell</td>
<td colspan="3">Spanning cell</td>
</tr>
<tr>
<td style="background: red">1</td>
<td style="background: blue">2</td>
<td style="background: green">3</td>
<td style="background: yellow">4</td>
</tr>
</table>

http://jsfiddle.net/07mno6r5/

关于css - 第一行单元格跨多列时的列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27911497/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com