多表头HTML表格布局不符预期,求修正方案
问题解决方法
你的表格第一行的colspan属性值设置错误——下方表格实际是6列,因此ROW A对应的th需要设置colspan="6",才能和下方的列完全对齐。
修改后的代码:
<table> <tr> <th colspan="6">ROW A</th> </tr> <tr> <th colspan="3">ROW B1</th> <th colspan="3">ROW B2</th> </tr> <tr> <th>RB1.1</th> <th>RB1.2</th> <th>RB1.3</th> <th>RB2.1</th> <th>RB2.2</th> <th>RB2.3</th> </tr> <tr> <td>a</td> <td>b</td> <td>c</td> <td>d</td> <td>e</td> <td>f</td> </tr> </table>
核心逻辑:表格的总列数由列数最多的行(比如你的第三行有6个th)决定,跨列元素的colspan值必须匹配总列数,否则浏览器会自动调整列宽,导致布局错位。
内容的提问来源于stack exchange,提问作者podesclease
相关产品推荐
相关产品推荐

