There is another common technique, based upon "absolute positioning" and negative top margin.
HTML:
<div class="foo">
<div class="bar">
Unknown stuff to be centered.
</div>
</div>
CSS:
.foo{
width:150px;
height:150px;
background:red;
position:relative;
}
.bar {
text-align: center;
position:absolute;
top:50%;
height:40px;
margin-top:-20px;
border:solid 1px blue;
}
The idea is that you move down to 50% from the top the inner div, and then push it up of half its height with negative margin-top.
Is very stable and cross-platform, the only constraint is you must know height of inner div.
To avoid this costraint, a workaround is replacing negative margin-top
with a transform: translateY(-50%);
. In this case, negative translation to center DIV is obtained visually with CSS transformation.
It's useful because in this way you can use it without knowing height of inner DIV, but remember that transformation are extracted from DOM rendering.