2010-09-08 20 views
1

我有一個非常簡單的問題。如何使用2個不同的頭文件重複子表頭並重復子頭文件(如示例1),還是將這些代碼分割成2個表格(見示例2)更好還是更具語義性?xhtml表 - 正確使用

例1:

<table> 
<tr> 
    <th colspan="3">HEADER 1</th> 
</tr> 
<tr> 
    <th>sub-header 1</th> 
    <th>sub-header 2</th> 
    <th>sub-header 3</th> 
</tr> 
<tr> 
    <td>data</td> 
    <td>data</td> 
    <td>data</td> 
</tr> 
<tr> 
    <td>data</td> 
    <td>data</td> 
    <td>data</td> 
</tr> 
<tr> 
    <th colspan="3">HEADER 2</th> 
</tr> 
<tr> 
    <th>sub-header 1</th> 
    <th>sub-header 2</th> 
    <th>sub-header 3</th> 
</tr> 
<tr> 
    <td>data</td> 
    <td>data</td> 
    <td>data</td> 
</tr> 
<tr> 
    <td>data</td> 
    <td>data</td> 
    <td>data</td> 
</tr> 

例2:

<table> 
    <tr> 
    <th colspan="3">HEADER 1</th> 
    </tr> 
    <tr> 
    <th>sub-header 1</th> 
    <th>sub-header 2</th> 
    <th>sub-header 3</th> 
    </tr> 
    <tr> 
    <td>data</td> 
    <td>data</td> 
    <td>data</td> 
    </tr> 
    <tr> 
    <td>data</td> 
    <td>data</td> 
    <td>data</td> 
    </tr> 
</table> 
<table> 
    <tr> 
    <th colspan="3">HEADER 2</th> 
    </tr> 
    <tr> 
    <th>sub-header 1</th> 
    <th>sub-header 2</th> 
    <th>sub-header 3</th> 
    </tr> 
    <tr> 
    <td>data</td> 
    <td>data</td> 
    <td>data</td> 
    </tr> 
    <tr> 
    <td>data</td> 
    <td>data</td> 
    <td>data</td> 
    </tr> 
</table> 
+0

如果您希望所有這些列互相排列,請使用一張表。 – 2010-09-08 00:34:00

回答

1

這是更好/更語義,因爲你需要傳達你想要傳達的信息,使用盡可能多或儘可能少的表。如果你不使用HTML,並且說爲了別人的理解而將數據放在一張紙上,你會使用零個,一個,兩個還是多個表?這就是你應該使用多少桌子。

+0

...並且不要忘記你可以使用多個'tbody's – user123444555621 2010-09-09 00:30:17