我想要的表头:
<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>
Run Code Online (Sandbox Code Playgroud)
问题是无论我如何设置宽度,第二行保持不变.我尝试了百分比和固定的像素宽度.
从样式中删除表格布局似乎工作,但我需要固定的布局.有没有办法在保持"表格布局:固定"的同时做到这一点?
我希望最后的布局看起来像这样但是使用表格布局:固定/
表和列宽度由table和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>
Run Code Online (Sandbox Code Playgroud)
见演示:http://jsfiddle.net/rRJU7/2/