Created
September 25, 2014 12:36
-
-
Save keithdevon/c35d84ccd1afdc4ba40c to your computer and use it in GitHub Desktop.
Responsive vertically centered images
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 class="responsive-container responsive-container--square"> | |
<img class="vertically-centered" src="path/to/image.jpg" /> | |
</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
.responsive-container { | |
position: relative; | |
padding-top: 0px; /* change this to accommodate YouTube chrome, e.g. 35px */ | |
height: 0; | |
overflow: hidden; | |
background: white; | |
} | |
.responsive-container--square { | |
padding-bottom: 100%; | |
} | |
.responsive-container--16x9 { | |
padding-bottom: 56.25%; | |
} | |
.responsive-container--4x3 { | |
padding-bottom: 75%; | |
} | |
.vertically-centered { | |
position: absolute; | |
top:50%; | |
left: 0; | |
width: 100%; | |
height: auto; | |
transform: translateY(-50%); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment