Vertically centering absolute text

http://stackoverflow.com/questions/10939288/how-can-i-vertically-center-text-in-a-dynamically-high-div

by Glen Cheney

HTML

<div class="container">
    <div class="text">
        <div>Text</div>
        <h2>More text</h2>
    </div>
</div>

CSS

.container {
    position: absolute;
    background: blue; 
    color: white;
    font-family: sans-serif;
    text-align: center; /* horizontally center */
    height: 100%; /* any height */
    width: 100%;
}

/* Ghost */
.container:before {
    content: '';
    width: 0;
    height: 100%;
    vertical-align: middle;
    display: inline-block;
}

.container .text {
    margin: 0;        
    vertical-align: middle;
    display: inline-block;
}

JavaScript

/* Vertically centering absolute text */