HTML 5 <table> 標簽
定義和用法
<table> 標簽定義 HTML 表格。
一個簡單的 HTML 表格包括 table 元素,一個或多個 tr、th 以及 td 元素。
tr 元素定義表格行,th 元素定義表頭,td 元素定義表格單元。
更復雜的 HTML 表格也可能包含 caption, col, colgroup, thead, tfoot, tbody 等元素。
實例
簡單的 HTML 表格,包含兩列兩行:
<table border="1"> <tr> <th>月份</th> <th>存款</th> </tr> <tr> <td>一月</td> <td>1000 元</td> </tr> </table>
瀏覽器支持
所有主流瀏覽器都支持 <table> 標簽。
HTML 4.01 與 HTML 5 之間的差異
在 HTML5 中,僅支持 "border" 屬性,并且只允許使用值 "" 或 "1"。
屬性
屬性 | 值 | 描述 |
---|---|---|
border |
| 規定表格單元是否擁有邊框。 |
cellpadding | pixels | HTML5 中不支持。 |
cellspacing | pixels | HTML5 中不支持。 |
frame |
| HTML5 中不支持。 |
rules |
| HTML5 中不支持。 |
summary | text | HTML5 中不支持。 |
width |
| HTML5 中不支持。 |
全局屬性
<table> 標簽支持 HTML 5 中的全局屬性。
事件屬性
<table> 標簽支持 HTML 5 中的事件屬性。