如何设置表格布局的两行标题表的宽度:固定?

时间:2012-12-12 14:14:29

标签: html

我想要的表头:

<table class="tabel_op_panou" style="margin: 0px 2px 0px 2px; width: 99%; table-layout:fixed;">
<tr>
    <th rowspan="2" style="width: 35%;">A</th>
    <th colspan="2" style="width: 25%;">B</th>
    <th colspan="3" style="width: 40%;">C</th>
</tr>
<tr>
    <th style="width: 8%;">B1</th>
    <th style="width: 17%;">B2</th>
    <th style="width: 8%;">C1</th>
    <th style="width: 17%;">C2</th>
    <th style="width: 15%;">C3</th>
</tr>

问题是无论我如何设置宽度,第二行保持不变。我尝试了百分比和固定的像素宽度。

从样式中删除表格布局似乎可行,但我需要固定的布局。在保持“table-layout:fixed”的同时有没有办法做到这一点?

我希望最后的布局看起来像this,但是使用表格布局:fixed /

1 个答案:

答案 0 :(得分:5)

table-layout:fixed

  

表格和列宽由表格宽度和 col 设置   元素或第一行单元格的宽度。细胞在   后续行不会影响列宽。

因此,您可以像这样修改代码:

<table class="tabel_op_panou" style="margin: 0px 2px 0px 2px; width: 99%;border:1px solid grey;table-layout:fixed;">
    <col style="width: 35%;"/>
    <col style="width: 8%;"/>
    <col style="width: 17%;"/>
    <col style="width: 8%; "/>
    <col style="width: 17%;"/>
    <col style="width: 15%;"/>
<tr>
    <th rowspan="2" style="width: 35%; border:1px solid grey;">A</th>
    <th colspan="2" style="width: 25%; border:1px solid grey;">B</th>
    <th colspan="3" style="width: 40%; border:1px solid grey;">C</th>
</tr>
<tr>
    <th style="width: 8%; border:1px solid grey;">B1</th>
    <th style="width: 17%; border:1px solid grey;">B2</th>
    <th style="width: 8%; border:1px solid grey;">C1</th>
    <th style="width: 17%; border:1px solid grey;">C3</th>
    <th style="width: 15%; border:1px solid grey;">C4</th>
    </tr>
</table>

请参阅演示:http://jsfiddle.net/rRJU7/2/

相关问题