Skip to content

Instantly share code, notes, and snippets.

@alexcican
Last active July 9, 2016 09:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcican/7000200 to your computer and use it in GitHub Desktop.
Save alexcican/7000200 to your computer and use it in GitHub Desktop.
Centring a div vertically and horizontally with CSS Flexbox (tested on Chrome 30, Safari 6, Firefox 24, Mobile Safari iOS 7, Mobile IE 10)
.parent {
display: flex;
height: 500px;
}
.child {
max-width: 20em;
margin: auto;
border: solid 1px;
}
/* alternative */
.flexcontainer {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment