Skip to content

Instantly share code, notes, and snippets.

@hlashbrooke
Last active December 19, 2015 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlashbrooke/5983684 to your computer and use it in GitHub Desktop.
Save hlashbrooke/5983684 to your computer and use it in GitHub Desktop.
Two methods for vertical centering in CSS
<div id="outer">
<div id="inner">Element to be aligned</div>
</div>
#outer {
display: table;
width: 100%;
height: 100%; /* Height can be anything */
}
#inner {
display: table-cell;
vertical-align: middle;
text-align: center;
}
#outer {
width: 100%; /* Firefox needs this */
height: 100%; /* Height can be anything */
/* WebKit (Chrome & Safari) */
display: -webkit-box;
-webkit-box-pack: center;
-webkit-box-align: center;
/* Firefox */
display: -moz-box;
-moz-box-pack: center;
-moz-box-align: center;
/* IE */
display: -ms-box;
-ms-box-pack: center;
-ms-box-align: center;
/* Native CSS */
display: box;
box-pack: center;
box-align: center;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment