Last active
February 3, 2017 12:21
-
-
Save joshuacerbito/2989258b71e5792a7e7fc36425040073 to your computer and use it in GitHub Desktop.
Aspect Ratio Handler Mixin
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
/*---------------------------------------------------------------*\ | |
ASPECT RATIO HANDLER | |
preserves the aspect ratio of an element | |
usage: | |
@include aspect-ratio(16, 9); | |
note: | |
you can use this link to find your desired aspect ratio | |
http://andrew.hedges.name/experiments/aspect_ratio/ | |
or you can just use the original dimensions of your element | |
e.g. | |
@include aspect-ratio(1280, 720); | |
\*---------------------------------------------------------------*/ | |
@mixin aspect-ratio($w, $h, $bgs: cover, $bgpx: center, $bgpy: center) { | |
overflow: hidden; | |
position: relative; | |
background-size: $bgs; | |
background-position: $bgpx $bgpy; | |
background-repeat: no-repeat; | |
&:before { | |
padding-bottom: $h * 100% / $w; | |
display: block; | |
content: ''; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment