1
0
mirror of https://github.com/locomotivemtl/locomotive-boilerplate.git synced 2026-01-15 00:55:08 +08:00

Create aspect-ratio SCSS mixin polyfill

This commit is contained in:
Lucas Vallenet
2023-08-14 10:40:24 +02:00
parent e9dbb03207
commit dc0bc2042c
2 changed files with 32 additions and 1 deletions

View File

@@ -193,3 +193,34 @@
display: $display $important;
visibility: visible $important;
}
// Aspect-ratio polyfill
//
// The element will be accessible from screen readers and visible in the document flow.
//
// @param {Number} $ratio [19/6] - The ratio of the element.
// @param {Number} $width [100%] - The width of element.
// @param {Boolean} $children [false] - Whether the element contains children.
// @output Properties for maintaining aspect-ratio
@mixin aspect-ratio($ratio: math.div(16, 9), $width: 100%, $children: false) {
@supports not (aspect-ratio: 1) {
aspect-ratio: $ratio;
}
@supports (aspect-ratio: 1) {
height: 0;
padding-top: calc(#{$width} * #{math.div(1, $ratio)});
@if ($children == true) {
position: relative;
> * {
position: absolute;
top: 0;
left: 0;
}
}
}
}