Skip to content

Instantly share code, notes, and snippets.

@mrchimp
Created August 5, 2019 12:30
Show Gist options
  • Select an option

  • Save mrchimp/e5960716f16758124628ef170a280c98 to your computer and use it in GitHub Desktop.

Select an option

Save mrchimp/e5960716f16758124628ef170a280c98 to your computer and use it in GitHub Desktop.
Fixed Ratios with SCSS
@function percentage($amount, $total) {
@return ($amount / $total) * 100;
}
@mixin ratio($width, $height) {
position: relative;
&::before {
content: '';
float: left;
padding-bottom: percentage($height, $width) * 1%;
}
&::after {
clear: left;
content: '';
display: table;
}
}
.is-3x2 {
@include ratio(3, 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment