Skip to content

Instantly share code, notes, and snippets.

@hrallo
Created November 17, 2021 19:20
Show Gist options
  • Save hrallo/a1fe86f02533b4378e82f5ff6d4e8433 to your computer and use it in GitHub Desktop.
Save hrallo/a1fe86f02533b4378e82f5ff6d4e8433 to your computer and use it in GitHub Desktop.
// aspect-ratio()
//
// Use on a container that you want to maintain a specific aspect ratio when scaling
//
// $width - in pixels
// $height - in pixels
@mixin aspect-ratio($width, $height) {
position: relative;
&:before {
display: block;
content: '';
width: 100%;
padding-top: ($height / $width) * 100%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment