2010-08-14 131 views

回答

20

這並不違反定義。但是,你應該使用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> 
7

您可以使用colspan,但包含colspan值的總和應該相等,以便表格正確呈現。

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

第一行具有一個小區,但它跨越因爲colspan的2個細胞中,第二行具有兩個單元,這是完全有效的。

3

是的,可以。table > tr > tdtd包含的內容。 Td參考:http://www.htmlcodetutorial.com/tables/_TD.html。在該參考文獻中,您可以看到TD有兩個屬性:colspanrowspan。通過使用這兩個屬性,表格可以在不同行上具有不同數量的單元格。
演示:

<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> 
2

是的,你可以做一個HTML表格,並留下了一些行<td>元素,但是這被認爲是不好的形式,因爲你不能確定HTML渲染器(瀏覽器)如何處理這種情況。不同的瀏覽器可能會略有不同。

定義每行顯示不同數量單元格的表格的推薦方法是使用colspan將兩個或更多個相鄰單元格合併爲一個。這將使最右邊的單元格與正確的列保持一致,並消除您希望HTML呈現器執行的任何含糊不清的操作。

2

您使用:

<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> 

相關問題