html裏表格由 <table> 標籤來定義。每一個表格均有若干行(由 <tr> 標籤訂義),每行被分割爲若干單元格(由 <td> 標籤訂義)。字母 td 指表格數據(table data),即數據單元格的內容。數據單元格能夠包含文本、圖片、列表、段落、表單、水平線、表格等等。html
表格的編寫:瀏覽器
<table border="1px"> <tr> <td>123</td> <td>123</td> </tr> <tr> <td>123</td> <td>123</td> </tr> </table>
若是不定義邊框屬性,表格將不顯示邊框;ide
表格的表頭使用 <th> 標籤進行定義。spa
大多數瀏覽器會把表頭顯示爲粗體居中的文本:orm
<table border="1"> <tr> <th>1</th> <th>2/th> </tr>
在一些瀏覽器中,沒有內容的表格單元顯示得不太好。若是某個單元格是空的(沒有內容),瀏覽器可能沒法顯示出這個單元格的邊框;爲了不這種狀況,在空單元格中添加一個空格佔位符,就能夠將邊框顯示出來。例:htm
<td></td>紅色爲空格佔位符
下面是幾個表格標籤:
圖片
表格 | 描述 |
---|---|
<table> | 定義表格 |
<caption> | 定義表格標題。 |
<th> | 定義表格的表頭。 |
<tr> | 定義表格的行。 |
<td> | 定義表格單元。 |
<thead> | 定義表格的頁眉。 |
<tbody> | 定義表格的主體。 |
<tfoot> | 定義表格的頁腳。 |
<col> | 定義用於表格列的屬性。 |
<colgroup> | 定義表格列的組 |
<html>get
<body>
it
<h4>橫跨兩列的單元格:</h4>
io
<table border="1">
<tr>
<th>姓名</th>
<th colspan="2">電話</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
<h4>橫跨兩行的單元格:</h4>
<table border="1">
<tr>
<th>姓名</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">電話</th>
<td>555 77 854</td>
</tr>
<tr>
<td>555 77 855</td>
</tr>
</table>
</body>
</html>
表頭的顯示:
<html>
<body>
<h4>表頭:</h4>
<table border="1">
<tr>
<th>姓名</th>
<th>電話</th>
<th>電話</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
<h4>垂直的表頭:</h4>
<table border="1">
<tr>
<th>姓名</th>
<td>Bill Gates</td>
</tr>
<tr>
<th>電話</th>
<td>555 77 854</td>
</tr>
<tr>
<th>電話</th>
<td>555 77 855</td>
</tr>
</table>
</body>
</html>