CSS - Vertical centered modal
by katalin_2003
HTML
<section>
<div class="modal vertical-align center">
<p class="vertical-align center">This is a vertically centered modal.
<br>Pretty cool, eh?</p>
</div>
</section>
CSS
.vertical-align {
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.center {
margin: 0 auto;
text-align: center;
}
.modal {
background-color: #fff;
border: 5px solid #333;
width: 450px;
height: 300px;
}
/* ====================================
Base styling
==================================== */
body {
font-family: sans-serif;
}
h1, h2 {
text-align: center;
}
section {
display: block;
background: #c6e3b6;
margin: 0 auto 1em;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
height: 100%;
}