I have this table:
<table id="tabla">
<tbody>
<tr><th>row1</th><td>aaaa</td></tr>
<tr><th>row2</th><td>bbbb</td></tr>
<tr><th>row3</th><td>cccc</td></tr>
<figure><img src="image.png"/></figure></td></tr>
</tbody>
</table>
This organizes the information in rows... But I want to rotate it and display it in columns... I hope this is enough explanation for what I want:
How I have it now:
row1: aaaa
row2: bbbb
row3: cccc imag
How I want it:
row1 | row2 | row3
aaaa | bbbb | cccc
| imag
How can I do this with CSS?
To place an item at the top or bottom of its cell, insert the "VALIGN=" attribute within the code for that cell. To vertically align an entire row (e.g., placing all data in that row at the tops of the cells), insert the "VALIGN=" attribute within the code for that row.
The trick is to use display: inline-block; on the table rows and white-space: nowrap; on the table body.
The first trick is to use writing-mode: vertical-lr to get the text to run vertically. By itself, the text runs top to bottom, but we want it to run bottom to top, so we spin it around it with the transform: rotate(180deg) . The default transform origin is the center of the element, so this works out great.
Using float property: Use float property to set the alignment of element. The float value can be set to left or right. Output: Use Padding property Horizontally: Padding property is used to set the element align to Horizontally by using left and right padding.
If you are forced only to use CSS you can play with rotate :)
#table {
transform:rotate(90deg);
}
#table th, #table td{
transform:rotate(-90deg);
}
td {
height: 50px;
}
<table id="table">
<tbody>
<tr><th>row1</th><td>aaaa</td></tr>
<tr><th>row2</th><td>bbbb</td><td>bbbb</td><td>bbbb</td></tr>
<tr><th>row3</th><td>bbbb</td><td>bbbb</td><td>bbbb</td></tr>
</tbody>
</table>
This probably isn't the solution you're expecting, I would really encourage you to look at the new CSS Flexible Box Model instead of using HTML tables as it'll make your life much easier in these sort of scenarios.
If you're interested, take a look at my answer for a very similar question at Vertical Menu (+ Sub-Menu) stacks unnaturally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With