Issue
In a horizontal heading table, <thead>
comes after the <table>
and before <tbody>
such as the following,
<table>
<thead>
<tr>
<th colspan="2">The table header</th>
</tr>
</thead>
<tbody>
<tr>
<td>The table body</td>
<td>with two columns</td>
</tr>
</tbody>
</table>
How about in a vertical heading table? What is the (best) practice to put the <thead>
? I have seen the following without <thead>
,
<table style="width:100%">
<tbody>
<tr>
<th>Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 77 855</td>
</tr>
</tbody>
</table>
Thank you in advance for your help.
I tried W3Schools and MDN The Table Head element, although it said <thead>
is optional, is there any approach to include the element?
Solution
You don't need any <thead>
. However, for a vertical tables in particular, do not forget to add the scope
attribute to <th>
cells:
<table style="width:100%">
<tr>
<th scope="row">Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th scope="row">Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<th scope="row">Telephone:</th>
<td>555 77 855</td>
</tr>
</table>
(You can also omit the <tbody>
if there's nothing else in the table)
Answered By - Bergi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.