Last active
April 18, 2018 08:05
-
-
Save richarddewit/c5f66b212ce29a755e08311b94aea6d9 to your computer and use it in GitHub Desktop.
Aspect ratio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import 'aspect-ratio'; | |
// Implementation | |
.map-wrapper { | |
@include aspect-ratio(16, 9, '.map'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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