I am attempting to recreate a demonstration where the house image scales as the viewport height decreases. However, instead of using an <img>
, I would like to use a container that also includes absolutely positioned content (unable to provide all the details).
You can view my attempt here: https://jsfiddle.net/syhb7d2L/6/
The main challenge lies in maintaining the aspect ratio (square) of the div.container
. Traditional padding-top hacks are not suitable in this scenario, as the container's width needs to adjust as the height changes.
I experimented with using a 1x1 Pixel Image as a placeholder, but encountered issues with scaling within the container.
UPDATE: Following the suggestion in the response 10706764, utilizing the CSS aspect-ratio
property would be beneficial for modern browsers. Unfortunately, this solution is only supported in iOS 15 and above, which does not meet our requirements as we need compatibility with iOS 12 and newer versions (widely used).