Use a CSS custom property, --aspect-ratio, to define the desired aspect ratio. Set the container element to position: relative and height: 0. Calculate its height using the calc() function and the custom property.

1m read timeFrom 30secondsofcode.org
Post cover image
1 Comment