Skip to content

Instantly share code, notes, and snippets.

@hhff
Created February 1, 2016 16:36
Show Gist options
  • Save hhff/c8efc94c29f19cb834cd to your computer and use it in GitHub Desktop.
Save hhff/c8efc94c29f19cb834cd to your computer and use it in GitHub Desktop.
Medium - CSS for the Functional Programmer - Aspect Example
@mixin aspect-ratio($width, $height) {
position: relative;
&:before {
display: block;
content: "";
width: 100%;
padding-top: ($height / $width) * 100%;
}
> .content {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
}
.one-one {
@include aspect-ratio(1, 1);
}
.four-three {
@include aspect-ratio(4, 3);
}
.three-four {
@include aspect-ratio(3, 4);
}
.three-two {
@include aspect-ratio(3, 2);
}
.sixteen-nine {
@include aspect-ratio(16, 9);
}
.three-one {
@include aspect-ratio(3, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment