你可(kě)以使用 HTML 創建表格。
表格
表格由 <table> 标簽來定義。每個表格均有若幹行(xíng)(由 <tr> 标簽定義),每行(xíng)被分割為(wèi)若幹單元格(由 <td> 标簽定義)。字母 td 指表格數(shù)據(table data),即數(shù)據單元格的內(nèi)容。數(shù)據單元格可(kě)以包含文本、圖片、列表、段落、表單、水平線、表格等等。
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
在浏覽器顯示如(rú)下(xià):
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
表格和(hé)邊框屬性
如(rú)果不定義邊框屬性,表格将不顯示邊框。有時(shí)這(zhè)很(hěn)有用,但(dàn)是大多數(shù)時(shí)候,我們希望顯示邊框。
使用邊框屬性來顯示一(yī)個帶有邊框的表格:
<table border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>
表格的表頭
表格的表頭使用 <th> 标簽進行(xíng)定義。
大多數(shù)浏覽器會把表頭顯示為(wèi)粗體居中的文本:
<table border="1">
<tr>
<th>Heading</th>
<th>Another Heading</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
在浏覽器顯示如(rú)下(xià):
Heading Another Heading
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
表格中的空單元格
在一(yī)些浏覽器中,沒有內(nèi)容的表格單元顯示得不太好。如(rú)果某個單元格是空的(沒有內(nèi)容),浏覽器可(kě)能(néng)無法顯示出這(zhè)個單元格的邊框。
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td></td>
<td>row 2, cell 2</td>
</tr>
</table>
表格 | 描述 |
---|---|
<table> | 定義表格 |
<caption> | 定義表格标題。 |
<th> | 定義表格的表頭。 |
<tr> | 定義表格的行(xíng)。 |
<td> | 定義表格單元。 |
<thead> | 定義表格的頁眉。 |
<tbody> | 定義表格的主體。 |
<tfoot> | 定義表格的頁腳。 |
<col> | 定義用于表格列的屬性。 |
<colgroup> | 定義表格列的組。 |