Last active
December 9, 2022 20:18
-
-
Save brianmcallister/2932463 to your computer and use it in GitHub Desktop.
Sass mixin for a responsive box that maintains an aspect ratio.
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
// Maintain ratio mixin. Great for responsive grids, or videos. | |
// https://gist.github.com/brianmcallister/2932463 | |
// | |
// $ratio - Ratio the element needs to maintain. | |
// | |
// Examples | |
// | |
// // A 16:9 ratio would look like this: | |
// .element { | |
// @include maintain-ratio(16 9); | |
// } | |
@mixin maintain-ratio($ratio: 1 1) { | |
@if length($ratio) < 2 or length($ratio) > 2 { | |
@warn "$ratio must be a list with two values."; | |
} | |
$width: 100%; | |
$height: percentage(nth($ratio, 2) / nth($ratio, 1)); | |
width: $width; | |
height: 0; | |
padding-bottom: $height; | |
} |
Brian,
What's the license for the use of this gist?
Note this fails in the current Firefox
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget the semicolon...
@warn "$ratio must be a list with two values.";