You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多表头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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 15:05:43