Skip to content

Instantly share code, notes, and snippets.

@adamfaux85
Last active August 14, 2018 11:04
Show Gist options
  • Save adamfaux85/faf7da28c369990be1f968db32f74aed to your computer and use it in GitHub Desktop.
Save adamfaux85/faf7da28c369990be1f968db32f74aed to your computer and use it in GitHub Desktop.
CSS Set aspect ratio for an element
// 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