I have an absolutly positioned element with content inside. It can be a or a few
tag. So I don\'t know the height of the content.
This can be done with flexbox too:
#absolute {
align-items: center;
display: flex;
justify-content: center;
}
if you add display:table
to your #absolute
div you should get what you want:
http://jsfiddle.net/3KTUM/2/
Horizontal and vertical position absolute middle.
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50% , -50%);
-webkit-transform: translate(-50%, -50%);
}
<div class="obj">
<div class="center">Test</div>
</div>
Change your #absolute
div to also use:
display:table;
vertical-align:middle;
text-align:center;
http://jsfiddle.net/3KTUM/4/