I want to show an HTML table with a caption on top and a horizontal line underneath, like this:
I see two ways to implement this, but both have their respective downsides. First method is like this:
<table>
<caption><b>***** yada yada yada *****</b></caption>
<tr>
<th></th>
<th>lorem</th>
<th>ipsum</th>
<th>dolor</th>
<th>sit</th>
<th>amet</th>
</tr>
<tr>
<th>hello</th>
<td>note</td>
<td>the</td>
<td>hori</td>
<td>zontal</td>
<td>line</td>
</tr>
<tr>
<th>world</th>
<td>under</td>
<td>neath:</td>
<td>2nd</td>
<td>caption??</td>
<td>tfoot??</td>
</tr>
<tfoot>
<tr>
<td colspan="6">
<hr>
</td>
</tr>
</tfoot>
</table>
What I don't like about this is that I have to use the colspan attribute; you know, the real table is generated from data, and finding out the colspan means some extra JavaScript I have to write, if I do it like this.
The other way would be like this:
<table>
<caption><b>***** yada yada yada *****</b></caption>
<caption style="caption-side: bottom;">
<hr>
</caption>
<tr>
<th></th>
<th>lorem</th>
<th>ipsum</th>
<th>dolor</th>
<th>sit</th>
<th>amet</th>
</tr>
<tr>
<th>hello</th>
<td>note</td>
<td>the</td>
<td>hori</td>
<td>zontal</td>
<td>line</td>
</tr>
<tr>
<th>world</th>
<td>under</td>
<td>neath:</td>
<td>2nd</td>
<td>caption??</td>
<td>tfoot??</td>
</tr>
</table>
By using caption instead of tfoot, I don't have to give the colspan, which is good. But the table already has a caption, and the second caption is not compliant with the spec.
The second method is simpler and looks just fine in all browsers I tested with, so I'm preferring that - browsers seem to be able to handle lot's of 'meaningful violations' of the spec. But it doesn't feel 100% comfortable to be 'naughty' like that.
Q1: Is there a way to do this without tfoot and colspan, while being spec compliant at the same time?
Q2: do the above methods really look the same in all browsers?
border-bottom:1px solid black;
?table {border-bottom: 1px solid black;}
? @ScottMarcus GMTA (4 seconds) :)