<h1>Vertical Center using CSS Grid</h1>
<div class="vertical-centered-container">
<h2 class="vertical-centered-text">This should be centered</h2>
</div>
<p>Support: Every browser but IE</p>
.vertical-centered-container {
display: grid;
height: 50%;
.vertical-centered-text {
margin: auto;
}
}
/* just for the demo */
@import url(https://fonts.googleapis.com/css?family=Roboto:300);
html,body {height: 100%;}
body {
font-family: 'Roboto', 'sans-serif';
background-color: #e74c3c;
color: white;
text-align: center;
}
h1,h2,p {
font-weight: 300;
font-size: 2em;
text-shadow: #c0392b 2px 2px 1px;
}
p {
text-transform: uppercase;
font-size: 1em;
}
div {
margin: 5% auto;
width: 80%;
height: 200px;
border: 2px solid #c0392b;
border-radius: 6px;
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.