I am facing an issue with a table displaying vertical text in the header. Here is a simplified example:
HTML & CSS
div.vertical {
margin-left: -100px;
position: absolute;
width: 215px;
transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
}
th.vertical {
height: 220px;
line-height: 14px;
padding-bottom: 25px;
text-align: left;
}
td,
th {
padding: 5px;
border-top: 1px solid #dddddd;
border-left: 1px solid #dddddd;
}
<div class="row" style="margin-top: 20px;margin-left: 10px;">
<div class="col-md-12">
<div class="table-responsive">
<table>
<thead>
<tr>
<th class="vertical">
<div class="vertical">Really long and complex 1</div>
</th>
<th class="vertical">
<div class="vertical">Really long and complex 2</div>
</th>
<th class="vertical">
<div class="vertical">Really long and complex 3</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>AH</td>
<td>BH</td>
<td>HH</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
When there are many columns, the table container starts scrolling. Take a look at this:
However, I noticed that the header does not scroll along when the rest of the table is scrolled. This was due to using position: absolute
in the div.vertical
class. Removing this style makes the header scroll but causes the header width to increase significantly. You can see it here:
Is there a way to achieve both scrolling functionality and maintain a small header width using only CSS? Thank you!