aspect-ratio

Sets the fixed aspect ratio of the element via padding hack with ::before pseudo-element.

Arguments

NameTypeDefaultDescription
$width *numberThe needed element width.
$heightnumber$widthThe needed element height.

Example

@use 'more-sass' as more;

.element {
    @include more.aspect-ratio(1280px, 720px); // 16:9
}
.element {
    display: block;
    position: relative;
}

.element::before {
    content: '';
    display: block;
    padding-top: 56.25%;
}
Edit this page on GitHub Updated at Mon, Jan 30, 2023