【问题标题】:Html table - why does my third row appear in secondHtml 表 - 为什么我的第三行出现在第二行
【发布时间】:2015-01-09 18:05:00
【问题描述】:

为什么下面的 html 生成一个 2x2 单元格而不是 3 行的表格,第一个有 2 个单元格,接下来的 2 个有一个单元格跨越 2 个?

<table cellpadding="5" width="200">
    <tr>
        <td><img id="Button1_logoImg" src="" style="height:75px;width:75px;" alt="sButton1_logoImg" /></td><td><img id="Button1_errorImg" src="" style="height:50px;width:50px;" alt="Button1_logoImg" /></td>
    </tr>
    <tr>
        <td width="100%" rowspan="2"><input name="Button1$mainTextTb" type="text" value="changed" id="Button1_mainTextTb" style="font-size:20pt;width:180px;" /></td>
    </tr>
    <tr>
        <td rowspan="2" width="100%"><span id="Button1_subTextLbl" style="font-size:12pt;">sub text</span></td>
    </tr>
</table>

【问题讨论】:

  • 因为第 2 行的行跨度为 2?
  • 天哪 - 我需要第二行跨越表格的宽度,即 2 个单元格。

标签: html html-table row cell


【解决方案1】:

将第 2 行和第 3 行中的 rowspan 替换为 colspan。

【讨论】:

    【解决方案2】:

    你的代码

    <table cellpadding="5" width="200">
        <tr>
            <td><img id="Button1_logoImg" src="" style="height:75px;width:75px;" alt="sButton1_logoImg" /></td><td><img id="Button1_errorImg" src="" style="height:50px;width:50px;" alt="Button1_logoImg" /></td>
        </tr>
        <tr>
            <td width="100%" rowspan="2"><input name="Button1$mainTextTb" type="text" value="changed" id="Button1_mainTextTb" style="font-size:20pt;width:180px;" /></td>
        </tr>
        <tr>
            <td rowspan="2" width="100%"><span id="Button1_subTextLbl" style="font-size:12pt;">sub text</span></td>
        </tr>
    </table>
    

    将行跨度替换为列跨度

    修改后的代码

      <table cellpadding="5" width="200">
            <tr>
                <td><img id="Button1_logoImg" src="" style="height:75px;width:75px;" alt="sButton1_logoImg" /></td><td><img id="Button1_errorImg" src="" style="height:50px;width:50px;" alt="Button1_logoImg" /></td>
            </tr>
            <tr>
                <td width="100%" colspan="2"><input name="Button1$mainTextTb" type="text" value="changed" id="Button1_mainTextTb" style="font-size:20pt;width:180px;" /></td>
            </tr>
            <tr>
                <td colspan="2" width="100%"><span id="Button1_subTextLbl" style="font-size:12pt;">sub text</span></td>
            </tr>
        </table>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-02
      • 1970-01-01
      • 2015-04-21
      • 2021-09-09
      相关资源
      最近更新 更多