The table I am trying to design is going to end up to be somewhat dynamic. I would like the table header cells to appear rotated (to save horizontal space). I am aware there might be better methods to save some table space, but as I was playing around with some HTML, I got interested in something that seemed quite impossible.
Within following piece of code I tried to rotate the cells:
th {
background-color: #ccc;
}
th,
td {
border: 1px solid #000;
}
.rotate {
transform: rotate(-90deg);
text-align: center;
margin-bottom: 100px;/* <-- Anything I could do here? */
}
<table cellspacing="0" cellpadding="0">
<thead>
<tr>
<th class="rotate">
Foo
</th>
<th class="rotate">
Bar
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Foo collection
</td>
<td>
Bar collection
</td>
</tr>
</tbody>
</table>
I found some code in a couple other questions in order to address my issue(s), however most of these questions do not address the issue(s) I am having:
Whenever given table cell's content would increase (e.g. more characters and/or words), content would flow either outside of the given cell or break the appearance of the cell.
First off I would like my table cells to stay where they are supposed to (so no hovering over other cells like what is happening in my fiddle above):
and secondly I would like to be able to adjust the text inside these cells, meaning that the cells must be able to resize without breaking the table's layout:
In other words: I would like to create rotated table header cells without losing any of HTML's table default functionalities. Is it possible to rotate a table header cell (<th>
element) without breaking the table?