How can I make the table header appear on the left side of the table as a column instead on the top as a row? I have this markup:
<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>
I needed something a little different, but the answers by @alex and @marion got me started in the right direction. The problem was that when you needed many items in the table, the "columns" started stacking funny on smaller screens.
Thanks to Serge for his answer here that led me in this solution. This solution allows for scrolling horizontally and doesn't stack funny regardless of the size of the screen/window. I tested it in Chrome, Firefox, Opera, Edge, and IE11. Here's the fiddle with the correct alignment for the new "rows" and "columns": https://jsfiddle.net/berrym/6r3zvaef/21/
And just in case it disappears from JSFiddle:
If you use bootstrap, you can achieve this easily with the
table-reflow
style: http://v4-alpha.getbootstrap.com/content/tables/#reflowYou can see the result here. You mean like this?
You usually use
rowspan
andcolspan
for cells spanning multiple columns/rows.Just use
<th>
as the first element in the row. Then add thescope
attribute, which has no visual impact, but you could use it e.g. in CSS.See also http://www.w3.org/TR/WCAG20-TECHS/H63
How's this?
Example
CSS
jsFiddle.
Update
jsFiddle.
It also looks like IE baulks at this. You may have to trade semantic-ness for cross browser compatibility.
This worked perfectly for me : (inspired from the first answer)
Example here
html :
css :