Skip to content

Instantly share code, notes, and snippets.

@ralexandr
Last active October 19, 2016 08:57
Show Gist options
  • Save ralexandr/a3c47880008755293af15e74b5f81b2b to your computer and use it in GitHub Desktop.
Save ralexandr/a3c47880008755293af15e74b5f81b2b to your computer and use it in GitHub Desktop.
SASS: Responsive ratio
// use this for creating scalable elements (usually images / background images) that maintain a ratio.
// @include responsive-ratio(16,9);
@mixin responsive-ratio($x,$y, $pseudo: false) {
$padding: unquote( ( $y / $x ) * 100 + '%' );
@if $pseudo {
&:before {
@include pseudo($pos: relative);
width: 100%;
padding-top: $padding;
}
} @else {
padding-top: $padding;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment