Splitting a table cell into two columns in HTML

前端 未结 8 931
感动是毒
感动是毒 2020-12-05 22:43

I have the following table:

Header Header
相关标签:
8条回答
  • 2020-12-05 23:07

    Like this http://jsfiddle.net/8ha9e/1/

    Add colspan="2" to the 3rd <th> and then have 4 <td>'s in your second row.

    <table border="1">
      <tr>
        <th scope="col">Header</th>
        <th scope="col">Header</th>
        <th scope="col" colspan="2">Header</th>
      </tr>
      <tr>
        <th scope="row">&nbsp;</th>
        <td>&nbsp;</td>
        <!-- The following two cells will appear under the same header -->
        <td>Col 1</td>
        <td>Col 2</td>
      </tr>
    </table>
    
    0 讨论(0)
  • 2020-12-05 23:11

    You have two options.

    1. Use an extra column in the header, and use <colspan> in your header to stretch a cell for two or more columns.
    2. Insert a <table> with 2 columns inside the td you want extra columns in.
    0 讨论(0)
  • 2020-12-05 23:13

    is that what your looking for?

    <table border="1">
    <tr>
     <th scope="col">Header</th>
     <th scope="col">Header</th>
     <th scope="col" colspan="2">Header</th>
    </tr>
    <tr>
     <th scope="row">&nbsp;</th>
     <td>&nbsp;</td>
     <td>Split this one</td>
     <td>into two columns</td>
    </tr>
    </table>  
    
    0 讨论(0)
  • 2020-12-05 23:14

    Change the <td> to be split to look like this:

    <td><table><tr><td>split 1</td><td>split 2</td></tr></table></td> 
    
    0 讨论(0)
  • 2020-12-05 23:15

    Use this example, you can split with the colspan attribute

    <TABLE BORDER>
         <TR>
             <TD>Item 1</TD>
             <TD>Item 1</TD>
             <TD COLSPAN=2>Item 2</TD>
        </TR>
        <TR>
             <TD>Item 3</TD>
             <TD>Item 3</TD>
             <TD>Item 4</TD>
             <TD>Item 5</TD>
        </TR>
    </TABLE>
    

    More examples at http://hypermedia.univ-paris8.fr/jean/internet/ex_table.html.

    0 讨论(0)
  • 2020-12-05 23:20

    Please try the following way.

    <table>
      <tr>
        <th>Month</th>
        <th>Savings</th>
      </tr>
      <tr>
        <td>January</td>
        <td>$100</td>
      </tr>
      <tr>
        <td>February</td>
        <td>$80</td>
      </tr>
      <tr>
        <td colspan="2">Sum: $180</td>
      </tr>
    </table>
    
    0 讨论(0)
提交回复
热议问题