Created
October 17, 2018 08:12
-
-
Save Yipee-ki-yay/26209bebed10648a438bfd142df4041f to your computer and use it in GitHub Desktop.
mixin 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) { | |
position: relative; | |
&:before { | |
display: block; | |
content: ""; | |
width: 100%; | |
padding-top: ($height / $width) * 100%; | |
} | |
> .inner-box { | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
} | |
} | |
/* | |
<!-- HTML --> | |
<div class="outer-box"> | |
<div class="inner-box"></div> | |
</div> | |
<!-- SCSS --> | |
.outer-box { | |
@include aspect-ratio(4, 3); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment