HTML 表格
HTML 表格
HTML 表格
表格由 <table> 標(biāo)簽來定義。每個表格均有若干行(由 <tr> 標(biāo)簽定義),每行被分割為若干單元格(由 <td> 標(biāo)簽定義)。字母 td 指表格數(shù)據(jù)(table data),即數(shù)據(jù)單元格的內(nèi)容。數(shù)據(jù)單元格可以包含文本、圖片、列表、段落、表單、水平線、表格等等。
表格實例
<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>
HTML 表格和邊框?qū)傩?/p>
如果不定義邊框?qū)傩?,表格將不顯示邊框。有時這很有用,但是大多數(shù)時候,我們希望顯示邊框。
使用邊框?qū)傩詠盹@示一個帶有邊框的表格:
<table border="1"> <tr> <td>Row 1, cell 1</td> <td>Row 1, cell 2</td> </tr> </table>
HTML 表格表頭
表格的表頭使用 <th> 標(biāo)簽進(jìn)行定義。
大多數(shù)瀏覽器會把表頭顯示為粗體居中的文本:
<html> <head> <table border="1"> <tr> <th>Header 1</th> <th>Header 2</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> </head> </html> 舉個例子: <html> <head> <meta charset="utf-8"> <title>無標(biāo)題頁</title> <style type="text/css"> .tb { border-width:1px; border-collapse:collapse; border-color:black; border-style:solid; } td { border-width:1px; border-collapse:collapse; border-color:black; border-style:solid; } </style> </head> <body> <div> <table width="600" height="400" border="1"> <tr> <td colspan="3"></td> </tr> <tr> <td rowspan="3"></td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </div> </body> </html>
HTML 表格標(biāo)簽
標(biāo)簽 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 描述
<table> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 定義表格
<th> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?定義表格的表頭
<tr> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?定義表格的行
<td> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 定義表格單元
<caption> ? ? ? ? ? ? ? ? ? ? ? ? ? ?定義表格標(biāo)題
<colgroup> ? ? ? ? ? ? ? ? ? ? ? ?定義表格列的組
<col> ? ? ? ? ? ? ? ? ? ? ? ? ? ? 定義用于表格列的屬性
<thead> ? ? ? ? ? ? ? ? ? ? ? ? ? ? 定義表格的頁眉
<tbod> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 定義表格的主體
<tfoot> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 定義表格的頁腳