HTML colspan和rowspan问题

时间:2018-06-30 08:55:00

标签: html

我在使用HTML colspanrowspan时遇到问题,我想合并第一列(名称)和最后一列(电话),但这给了我不想要的结果。 结果就是我想要的:

enter image description here

这是我得到的:

enter image description here

我的代码:

<table>
  <tr>
    <th colspan="3">Name</th>
    <th rowspan="2">Age</th>
    <th colspan="2">Telephone</th>
  </tr>
  <tr>
    <th>First name</th>
    <th>Middle name</th>
    <th>Last name</th>
  </tr>
  <tr>
    <th>pre</th>
    <th>post</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>David</td>
    <td>Smith</td>
    <td>50</td>
    <td>055</td>
    <td>5778541</td>
  </tr>
  <tr>
    <td>Roben</td>
    <td>Jill</td>
    <td>Adam</td>
    <td>35</td>
    <td>050</td>
    <td>5577854</td>
  </tr>
</table>

3 个答案:

答案 0 :(得分:2)

rowspan更改为colspan并确定colspan的值

<table border=1>
  <tr>
    <th colspan="3">Name</th>
    <th colspan="1">Age</th>
    <th colspan="2">Telephone</th>
  </tr>
  <tr>
    <th>First name</th>
    <th>Middle name</th>
    <th>Last name</th>
    <th></th>
    <th>pre</th>
    <th>post</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>David</td>
    <td>Smith</td>
    <td>50</td>
    <td>055</td>
    <td>5778541</td>
  </tr>
  <tr>
    <td>Roben</td>
    <td>Jill</td>
    <td>Adam</td>
    <td>35</td>
    <td>050</td>
    <td>5577854</td>
  </tr>
</table>

答案 1 :(得分:0)

从第二行开始,您必须填写所有列。

<table>
  <tr>
    <th colspan="3">Name</th>
    <th rowspan="1">Age</th>
    <th colspan="2">Telephone</th>
  </tr>
  <tr>
    <th>First name</th>
    <th>Middle name</th>
    <th>Last name</th>
    <th></th>
    <th>pre</th>
    <th>post</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>David</td>
    <td>Smith</td>
    <td>50</td>
    <td>055</td>
    <td>5778541</td>
  </tr>
  <tr>
    <td>Roben</td>
    <td>Jill</td>
    <td>Adam</td>
    <td>35</td>
    <td>050</td>
    <td>5577854</td>
  </tr>
</table>

答案 2 :(得分:0)

在前后添加四个空白标题标签 像这样的代码:

<table>
            <tr> 
                <th colspan="3">Name</th>
                <th rowspan="2">Age</th>
                <th colspan="2">Telephone</th>
            </tr>
            <tr>
                <th>First name</th>
                <th>Middle name</th>
                <th>Last name</th>
            </tr>
            <tr>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th>pre</th>
                <th>post</th>
            </tr>
            <tr> 
                <td>Jill</td>
                <td>David</td>
                <td>Smith</td> 
                <td>50</td>
                <td>055</td>
                <td>5778541</td>  
            </tr> 
            <tr> 
                <td>Roben</td>
                <td>Jill</td> 
                <td>Adam</td> 
                <td>35</td>
                <td>050</td>
                <td>5577854</td>
            </tr>
        </table>