Forked from knolaust/sass-aspect-ratio-with-fallback.scss
Created
October 12, 2022 20:46
-
-
Save olegopro/fe02dba199e3876ab98104b3a28d0e74 to your computer and use it in GitHub Desktop.
Sass Mixin For CSS Aspect-Ratio With Fallback
This file contains hidden or 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
/** | |
* Include this Sass mixin for aspect-ratio. Includes fallback | |
* for browsers that do not support aspect-ratio. This fallback is really not necessary at this point unless | |
* a specific browser you need to support. | |
* | |
* Usage: | |
* @include aspect-ratio(16,9); | |
* creates a 16x9 container using aspect-ratio for supported browsers with fallback for browsers that do not. | |
* | |
* Codepen Example: https://codepen.io/knolaust/pen/KKZwXjv | |
* | |
*/ | |
@mixin aspect-ratio($width, $height) { | |
aspect-ratio: $width / $height; | |
// Fallback (current, using padding hack) | |
@supports not (aspect-ratio: 1 / 1) { | |
&::before { | |
float: left; | |
padding-top: calc(100% * #{$height} / #{$width}); | |
content: ""; | |
} | |
&::after { | |
display: block; | |
content: ""; | |
clear: both; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment