Aspect ratio image card
With the aspect-ratio property, as you resize the card, the green visual block maintains this 16 x 9 aspect ratio. We are respecting the aspect ratio with aspect-ratio: 16 / 9.
.video {
aspect-ratio: 16 / 9;
}
To maintain a 16 x 9 aspect ratio without this property, you'd need to use a padding-top hack and give it a padding of 56.25% to set a top-to-width ratio. We will soon have a property for this to avoid the hack and the need to calculate the percentage. You can make a square with 1 / 1 ratio, a 2 to 1 ratio with 2 / 1, and really just anything you need for this image to scale with a set size ratio.
.square {
aspect-ratio: 1 / 1;
}
这篇文档对你有帮助吗?
谢谢你的反馈!