Last active
November 30, 2022 15:39
-
-
Save ozinepank/f38ea0f1d12e51137dd8 to your computer and use it in GitHub Desktop.
The Padding-Bottom Hack
This file contains hidden or 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
.img-container { | |
position: relative; | |
padding-bottom: 56.25%; /* 16:9 ratio */ | |
height: 0; | |
overflow: hidden; | |
} | |
.img-container img { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
} | |
/* Article : http://www.goldenapplewebdesign.com/responsive-aspect-ratios-with-pure-css/ | |
B / (A / 100) = C% | |
So for 16:9 (where 16 is A and 9 is B): | |
9 / .16 = 56.25 (%) | |
And that’s all there is to it! | |
Some Other Common Ratios | |
For the not so mathematically inclined, here are some of the percentages for common aspect ratios: | |
75% = 4:3 | |
66.66% = 3:2 | |
62.5% = 8:5 | |
100% = 1:1 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment