Created
January 10, 2016 15:24
-
-
Save simbasounds/97ac083e9f6d3d98800b to your computer and use it in GitHub Desktop.
Proportional size with vertical centring 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
/* Basic vertical centring (middle) */ | |
.container { | |
position: relative; | |
} | |
.content { | |
position: absolute; | |
top: 50%; | |
-webkit-transform: translateY(-50%); | |
-moz-transform: translateY(-50%); | |
-o-transform: translateY(-50%); | |
-ms-transform: translateY(-50%); | |
transform: translateY(-50%); | |
} | |
/* Proportional size */ | |
.container { | |
position: relative; | |
} | |
.container:after { | |
content: " "; | |
padding-top: 100%; | |
display: block; | |
} | |
.content { | |
position: absolute; | |
left: 0; | |
right: 0; | |
top: 0; | |
} | |
/* Proportional size with vertical centring */ | |
.container { | |
position: relative; | |
} | |
.container:after { | |
content: " "; | |
padding-top: 100%; | |
display: block; | |
} | |
.content { | |
position: absolute; | |
left: 0; | |
right: 0; | |
top: 50%; | |
-webkit-transform: translateY(-50%); | |
-moz-transform: translateY(-50%); | |
-o-transform: translateY(-50%); | |
-ms-transform: translateY(-50%); | |
transform: translateY(-50%); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment