I would like to size an hmtl div element proportionally to viewport's size.
This element would be positioned into a dynamically sized container so it's not possible to use viewport units both for element's width and height.
I'm trying as far as possible to do this in pure CSS/SASS, I tried to use the aspect-ratio property but can't manage to make it work
.element {
width: 80%; /*80% of container width*/
aspect-ratio: calc(100vw/100vh);
}
Can't be done without JavaScript.
In your case
calc(100vw/100vh)is an invalid expression. Docs here.Using JavaScript:
.viewport-ratioelement added to DOM after script has run won't have the ratio until theupdateRatiosruns again (or window is resized).