Created
August 31, 2021 17:31
-
-
Save dougkeeling/bdfeb8f5de2bd43eac56d8d3240ebb40 to your computer and use it in GitHub Desktop.
[Define an aspect ratio for a <div>] Set the width and height and the aspect ratio will be determined automatically. #scss #css
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%; | |
} | |
} | |
// Example | |
.div { | |
@include aspect-ratio(16,9); | |
width: 100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment