CONTAINER CENTER - CSS ONLY - BIZAMAJIG USAGE
by bizamajig
HTML
<div class="container-center">
<h1>Vertical center with only 3 lines of code</h1>
<section class="container-center-section">
<p>I'm vertically aligned! Hi ho Silver, away!</p>
</section>
</div>
CSS
.container-center {
position: absolute;
top: 50%;
left: 50%;
-moz-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
border: 2px solid red;
padding: 10px;
text-align: center;
}
.container-center-section p {
margin: 0;
position: relative;
top: 50%;
-moz-transform: translateY(-50%);
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
section {
display: block;
max-width: 500px;
background: #433669;
margin: 0 auto 1em;
height: 100px;
border-radius: .5em;
color: white;
padding: 1em;
}