Struggling to rotate text in an HTML table, I've encountered alignment and text flow issues no matter what. Various CSS combinations of writing-mode and rotate have been attempted but the problem persists. Here is the test table:
Code snippet:
table {
margin-left: auto;
margin-right: auto;
}
.c10 {
font-variant: small-caps;
}
.text-body-2-western {
text-align: center;
text-indent: 0em;
}
.c90bt {
-webkit-transform: rotate(270deg);
-moz-transform: rotate(270deg);
-ms-transform: rotate(270deg);
-o-transform: rotate(270deg);
transform: rotate(270deg);
}
<table cellpadding="2" cellspacing="0">
<col>
<col>
<col>
<tr>
<td rowspan="3">
<p class="text-body-2-western c90bt"><span class="c10">test title.</span><br>this is a test string of text rotated vertically that should fit within the table td limits.</p>
</td>
<td>
<p class="text-body-2-western">MAIN TITLE OF THE TABLE SHOULD CENTER HORIZONTALLY</p>
</td>
<td rowspan="3">
<p class="text-body-2-western c90bt"><span class="c10">test title.</span><br>this is a test string of text rotated vertically that should fit within the table td limits but for some reason reaches outside of it.</p>
</td>
</tr>
<tr>
<td>
<p class="text-body-2-western"><img src="https://universaltheosophy.com/resources/sd-2-300-blank.png"></p>
</td>
</tr>
<tr>
<td>
<p class="text-body-2-western text-body-no-spacing"><span class="c10">bottom title in small caps.</span></p>
</td>
</tr>
</table>
The main issues are at two places:
The rotated text doesn't align properly within the top and bottom boundaries of the table td element. It either extends outside or becomes squished together.
The horizontal alignment of the text is far off from the image at the center. Desired look is tight alignment between the rotated text and the image.
Edit
To address a comment regarding rowspans, here's the same table without them with similar outcomes:
table {
margin-left: auto;
margin-right: auto;
}
.c10 {
font-variant: small-caps;
}
.text-body-2-western {
text-align: center;
text-indent: 0em;
}
.c90bt {
-webkit-transform: rotate(270deg);
-moz-transform: rotate(270deg);
-ms-transform: rotate(270deg);
-o-transform: rotate(270deg);
transform: rotate(270deg);
}
<table cellpadding="5" cellspacing="0">
<col>
<col>
<col>
<tr>
<td colspan="3">
<p class="text-body-2-western">MAIN TITLE OF THE TABLE SHOULD CENTER HORIZONTALLY.</p>
</td>
</tr>
<tr>
<td>
<p class="text-body-2-western c90bt"><span class="c10">test title.</span><br>this is a test string of text rotated vertically that should fit within the table td limits.</p>
</td>
<td>
<p class="text-body-2-western"><img src="https://universaltheosophy.com/resources/sd-2-300-blank.png" class="img1"></p>
</td>
<td>
<p class="text-body-2-western c90bt"><span class="c10">test title.</span><br>this is a test string of text rotated vertically that should fit within the table td limits but for some reason reaches outside of it.</p>
</td>
</tr>
<tr>
<td colspan="3">
<p class="text-body-2-western text-body-no-spacing"><span class="c10">bottom title in small caps.</span></p>
</td>
</tr>
</table>