Skip to content

Instantly share code, notes, and snippets.

@yoSteve
Last active September 10, 2020 13:27
Show Gist options
  • Save yoSteve/6b9af201679697ae0f6e9204a6ea42bb to your computer and use it in GitHub Desktop.
Save yoSteve/6b9af201679697ae0f6e9204a6ea42bb to your computer and use it in GitHub Desktop.
A Sassy Mixin for maintaining a responsive aspect ratio. Include this on a wrapper element.
// For an aspect ratio of 16:9 use like this:
// .wrapper-element {
// @include aspect-ratio(16, 9);
// }
@mixin aspect-ratio($width, $height) {
position: relative;
overflow: hidden;
height: 0;
padding-top: calc(#{$height} / #{$width} * 100%);
*:first-child {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment