Skip to content

Instantly share code, notes, and snippets.

@richarddewit
Last active April 18, 2018 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richarddewit/c5f66b212ce29a755e08311b94aea6d9 to your computer and use it in GitHub Desktop.
Save richarddewit/c5f66b212ce29a755e08311b94aea6d9 to your computer and use it in GitHub Desktop.
Aspect ratio
@mixin aspect-ratio($width, $height, $content-selector: '.content') {
position: relative;
&:before {
display: block;
content: '';
width: 100%;
padding-top: ($height / $width) * 100%;
}
> #{$content-selector} {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
}
// Implementation
/////////////////
.map-wrapper {
@include aspect-ratio(16, 9, '.map');
}
// Result
/////////
.map-wrapper {
position: relative;
}
.map-wrapper:before {
display: block;
content: '';
width: 100%;
padding-top: 56.25%;
}
.map-wrapper > .map {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
@import 'aspect-ratio';
// Implementation
.map-wrapper {
@include aspect-ratio(16, 9, '.map');
}
/* Result */
.map-wrapper {
position: relative;
}
.map-wrapper:before {
display: block;
content: '';
width: 100%;
padding-top: 56.25%;
}
.map-wrapper > .map {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment