Skip to content

Instantly share code, notes, and snippets.

@nikitaeverywhere
Last active August 29, 2015 14:20
Show Gist options
  • Save nikitaeverywhere/304955d212b081757be3 to your computer and use it in GitHub Desktop.
Save nikitaeverywhere/304955d212b081757be3 to your computer and use it in GitHub Desktop.
Pure CSS solution for centering content always on middle center of parent relative block.
/*
Pure CSS solution for centering content always on middle center of parent relative block.
*/
.central {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: table;
}
.central > div {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.central > div > div {
display: inline-block;
}
<div style="position: relative; height: 100%;"> <!-- Any position:relative block or body -->
<div class="central">
<div>
<div>
Here goes centered content!
</div>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment