Skip to content

Instantly share code, notes, and snippets.

@b4z81
Last active December 31, 2015 01:09
Show Gist options
  • Save b4z81/7912635 to your computer and use it in GitHub Desktop.
Save b4z81/7912635 to your computer and use it in GitHub Desktop.
/*
1- Horizontally and vertically
Dynamic sized elements
*/
.parent { position: relative; }
.child {
position: absolute;
left: 50%;
top: 50%
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
/*
2- Horizontally and vertically
Static sized element
*/
.parent { position: relative; }
.child {
position: absolute;
left: 50%;
top: 50%
height: 250px;
width: 500px;
/* Translate element based on it's size */
margin-left: -125px;
marign-top: -250px;
}
/*
Vertically
Inline and inline-block elements in a static parent
*/
.parent { line-height: 500px; }
.child {
display: inline-block;
vertical-align: middle;
}
/*
Faking tables.
*/
.parent { display: table; }
.child {
display: table-cell;
vertical-align: middle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment