I created two rectangle divs (that need to remain 60px wide and 150px tall) with text inside of them. The text is meant to be aligned in the rectangles vertically, so I used transform: rotate(-90deg)
to angle the text vertically.
I want to have the text vertical AND centered in the boxes. Before rotating the text vertically, I centered the text using the display: table
and vertical-align: middle
method. This works perfectly when the text is horizontal. However after rotating the content, the text does not stay centered. The CSS still centers the text as if it were horizontal.
I tried using absolute/relative positioning to offset the text from the top and left side, but when I remove the display: table
and vertical-align: center
properties, the text disappears.
Any ideas on how I can center the vertically angled text while keeping the table properties? Any input would be greatly appreciated.
Fiddle: https://jsfiddle.net/sxchx6zm/3/
HTML
<div id="both">
<div class="rectangle">
<div class="vertical">Text Area 1</div>
</div>
<div class="rectangle">
<div class="vertical">Test Area 2</div>
</div>
</div>
CSS
.rectangle {
height: 150px;
width: 60px;
background-color: #d3d3d3;
border: 1px solid red;
display: table;
}
.vertical {
font-size: 16pt;
height: 150px;
max-width: 60px;
display: table-cell;
vertical-align: middle;
transform: rotate(-90deg);
white-space: nowrap;
}