I have the following HTML:
<div class="outer">
<div class="inner rotate">Centered?</div>
</div>
div.outer
is a narrow vertical strip. div.inner
is rotated 90 degrees. I would like the text "Centered?" to appear centered in its container div. I do not know the size of either div in advance.
This comes close: http://jsfiddle.net/CCMyf/2/. You can see from the jsfiddle that the text is vertically centered before the transform: rotate(-90deg)
style is applied, but is somewhat offset after. This is particularly noticeable when div.outer
is short.
Is it possible to center this text vertically without knowing any of the sizes in advance? I haven't found any values of transform-origin
that solve this problem.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…