I have a div that has a certain width and height. In that div I also have a text. I want to align that text to the center (horizontally) and to the middle (vertically). But the div also needs a position: absolute
. So it can be positioned inside another div.
But because of the absolute
the text won't align vertically anymore.
This is what I have:
<div style="z-index:20;
position: absolute;
border: 1px dotted #16232d;
width: 300px;
height: 200px;
line-height: 200px;
top:88px; left:31px;
display: table-cell;
line-height: normal;
font-size:32px;
text-align: center;
vertical-align: middle;">
Lorem ipsum dolor sit amet
</div>
Example: http://jsfiddle.net/s8jp5ohh/
The text will never contain any <br>
. So it's always one line. But it should automatically break to a new line when the text is larger than the width of the div. So I'd like to keep that functionality (like you can see in the fiddle).
Is there a way to align the text in the center, vertically and horizontally?