Kind of a silly question, but I've been seeing things such as tbody and thead/tfoot tags in other peoples tables.
Are thes开发者_开发百科e required even if they're empty for good markup? Or can I just leave them out?
The table sections (thead/tbody/tfoot) are optional. The table caption (caption) and column definitons (col/colgroup) are also optional.
In HTML (but not XHTML) the closing tag for rows and cells are also optional, so you could write a table as:
<table>
<tr>
<th>1
<th>2
<tr>
<td>3
<td>4
<tr>
<td>5
<td>6
</table>
It's however recommended that you close the tags to get better structure in the code. It also makes it a lot easier if you decide to change to XHTML.
They aren't required, but they let you do some more advanced things with headers and footers: http://www.htmldog.com/guides/htmladvanced/tables/
Those tags are not required and a page would validate even without them.
if you really need tables, you should use them. If you use tables only for design purposes you should switch to css-markup.
A simple correct table example:
<table>
<thead>
<tr>
<td>id</td>
<td>name</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>User1</td>
</tr>
<tr>
<td>2</td>
<td>User2</td>
</tr>
</tbody>
</table>
Yes, that is proper markup. Though they are optional You can read further on the W3Schools page.
The <tbody>
tag is only partially supported in all major browsers.
Tables may have multiple bodies, but when it only has one single body, the HTML tbody tag may be safely omitted.
精彩评论