表格跨度如何工作?

时间:2016-11-23 03:23:42

标签: html html-table

我想做什么: enter image description here

我写了什么:

<table>
    <TR>
        <TD ROWSPAN="4">left</TD>
        <TD ROWSPAN="12">middle</TD>
        <TD ROWSPAN="3">right</TD>
    </TR>
   <TR>
        <TD ROWSPAN="4">left2</TD>
        <TD ROWSPAN="3">right2</TD>
   </TR> 
    <TR>
        <TD ROWSPAN="4">left3</TD>
        <TD ROWSPAN="3">right3</TD>
    </TR>
  <TR>
        <TD ROWSPAN="3">right4</TD>
  </TR>
</table>

事实证明: enter image description here

我希望桌子有相同的高度,我可以用这种方式工作,但它的高度不一样:

 <table>
    <TR>
        <TD>left</TD>
        <TD ROWSPAN="12">middle</TD>
        <TD>right</TD>
    </TR>
   <TR>
        <TD>left2</TD>
        <TD>right2</TD>
   </TR> 
    <TR>
        <TD>left3</TD>
        <TD>right3</TD>
    </TR>
  <TR>
        <TD>right4</TD>
  </TR>
</table>

结果如下:

enter image description here

1 个答案:

答案 0 :(得分:2)

知道了!诀窍是总共有12 <tr> s,即使其中一些是空的

作为一个好奇心,我通过在excel中创建表,保存为html,并删除excel放在那里的所有内联样式来解决这个问题。

&#13;
&#13;
td {
  border: 1px solid black;
}
&#13;
<table>
 <tr>
  <td rowspan=4>left</td>
  <td rowspan=12>middle</td>
  <td rowspan=3>right</td>
 </tr>
 <tr>
 </tr>
 <tr>
 </tr>
 <tr>
  <td rowspan=3>right2</td>
 </tr>
 <tr>
  <td rowspan=4>left2</td>
 </tr>
 <tr>
 </tr>
 <tr>
  <td rowspan=3>right3</td>
 </tr>
 <tr>
 </tr>
 <tr>
  <td rowspan=4>left3</td>
 </tr>
 <tr>
  <td rowspan=3>right4</td>
 </tr>
 <tr>
 </tr>
 <tr>
 </tr>
</table>
&#13;
&#13;
&#13;