Skip to content

Instantly share code, notes, and snippets.

@stoplion
Forked from brianmcallister/maintain-ratio.scss
Created September 24, 2012 18:39
Show Gist options
  • Save stoplion/3777538 to your computer and use it in GitHub Desktop.
Save stoplion/3777538 to your computer and use it in GitHub Desktop.
Sass mixin for a responsive box that maintains an aspect ratio.
/*
Maintain ratio mixin.
@param {List} [$ratio] Ratio the element needs to maintain. A 16:9 ratio would look like this:
.element { @include maintain-ratio(16 9); }
*/
@mixin maintain-ratio($ratio: 1 1) {
$width: 100%;
$height: percentage(nth($ratio, 2) / nth($ratio, 1));
width: $width;
height: 0;
padding-bottom: $height;
}
@stevendavisphoto
Copy link

Thanks for this. Helped with a responsive video container I'm handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment