Last active
August 14, 2018 11:04
-
-
Save adamfaux85/faf7da28c369990be1f968db32f74aed to your computer and use it in GitHub Desktop.
CSS Set aspect ratio for an element
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
// This approach is based upon the elements width. | |
.element { | |
position: relative; | |
width: 100%; | |
display: block; | |
&:after { | |
display: block; | |
content: ''; | |
/* Square Aspect ratio */ | |
padding-top: 100%; | |
/* 16:9 Aspect Ratio */ | |
// padding-top: 56.25%; | |
/* 4:3 Aspect Ratio */ | |
// padding-top: 75%; | |
/* 3:2 Aspect Ratio */ | |
// padding-top: 66.66%; | |
/* 8:5 Aspect Ratio */ | |
// padding-top: 62.5%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment