Last active
December 19, 2015 16:28
-
-
Save hlashbrooke/5983684 to your computer and use it in GitHub Desktop.
Two methods for vertical centering in CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="outer"> | |
<div id="inner">Element to be aligned</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#outer { | |
display: table; | |
width: 100%; | |
height: 100%; /* Height can be anything */ | |
} | |
#inner { | |
display: table-cell; | |
vertical-align: middle; | |
text-align: center; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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