.test {
width: 20%;
background: red;
aspect-ratio: 1/1;
}
<div class="test"></div>
aspect-ratio: 1/1;
It works fine in other browsers except safari. But this code doesn't work in Safari. I was using macOS 11.2. I have now updated to macOS 11.5.2. As far as I know it supports safari but I could not fully understand the problem. Thank you from now. If there is any missing information, I will add it if you let me know.
You can add a fallback for that, this padding hack works for me 😉
.test {
aspect-ratio: 16/9;
// Fallback
@supports not (aspect-ratio: 16 / 9) {
&::before {
float: left;
padding-top: 56.25%;
content: "";
}
&::after {
display: block;
content: "";
clear: both;
}
}
}
Other aspects ratio:
padding-top: 100%
padding-top: 75%
padding-top: 66.67%
padding-top: 56.25%
Edit: I found this tool it helped me alot for other different aspect ratios https://ratiobuddy.com/
aspect-ratio as a css property is not supported in Safari prior to Safari 15, but the use of media queries with aspect-ratio @media: (aspect-ratio: 1/1)
is supported: https://caniuse.com/?search=aspect-ratio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With