代码之家  ›  专栏  ›  技术社区  ›  randomguy

HTML表格的行中可以有可变数量的单元格吗?

  •  16
  • randomguy  · 技术社区  · 16 年前

    或者单元格的总数应该等于 columns * rows

    在不同行上具有不同数量单元格的表似乎通过了W3验证程序。

    5 回复  |  直到 12 年前
        1
  •  27
  •   Sᴀᴍ Onᴇᴌᴀ    8 年前

    这并不违反定义。但是你应该使用 colspan 属性将列扩展到整行:

    <table>
      <tr>
        <td>Row with</td>
        <td>2 cols</td>
      </tr>
      <tr>
        <td colspan="2">Row with only one col</td>
      </tr>
    </table>
    

    如果单元格周围有边框,这也会有所帮助。

    <table>
      <tr>
        <td rowspan="2">First column in row 1 and row 2</td>
        <td>Second column in row 1</td>
      </tr>
      <tr>
        <td>second column in row 2</td>
      </tr>
    </table>
    
        2
  •  7
  •   Navnath Godse Kostiantyn Koval    13 年前

    你可以用 colspan ,但包括 科尔斯潘 值应相等,以便表正确呈现。

    <table>
      <tr>
         <td colspan="2">blah</td>
      </tr>
      <tr>
         <td>blah</td>
         <td>boo</td>
      </tr>
    </table>
    

    科尔斯潘 ,第二行有两个单元格,这是完全有效的。

        3
  •  3
  •   Bang Dao    16 年前

    在 table > tr > td td 是包含内容的。 Td 此处引用: http://www.htmlcodetutorial.com/tables/_TD.html 和
    演示:

    <table border="1">
         <tr>
              <td>a</td>
              <td>b</td>
         </tr>
         <tr> 
              <td colspan="2">c</td>
         </tr>
    </table>
    

    以及

    <table border="1">
         <tr>
              <td rowspan="2">a</td>
              <td>b</td>
         </tr>
         <tr> 
              <td>c</td>
         </tr>
    </table>
    
        4
  •  2
  •   dthorpe    16 年前

    是的,你可以制作一个HTML表格,然后把 <td>

    colspan

        5
  •  2
  •   binhhoang18    12 年前

    <table>
    <thead>
        <th>Column one</th>
        <th>Column two</th>
        <th>Column three</th>
    </thead>
    <tbody>
        <tr>
            <td rowspan="2">A large cell</td>
            <td>Another small cell0</td>
            <td>Another small cell0</td>
        </tr>
        <tr>
            <td>Another small cell1</td>
            <td>Another small cell1</td>
        </tr>
    </tbody>