Last active
September 10, 2020 13:27
-
-
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.
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
// 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