How can I create a div that
- has aspect-ratio 9/16
- always fully fits in the viewport without scrolling
- and is horizontally and vertically centered?
On a wide viewport it should look like this:
And on a narrow viewport like this:
Below is my approach that works as long as the viewport is wide, but fails when the viewport gets too narrow.
div {
border: 1px solid gray;
}
<div style="height: 100%;width: 100%;">
<div style="display: flex;justify-content: center; align-items: center;height: 100%;width: 100%;flex-direction: column;">
<div style="aspect-ratio: 9/16; max-width: 100%; height: 100%;">
<div style="width: 100%; height: 100%">
i should always have 9/16 aspect ratio and always be visible on the viewport without scrolling. but when viewport gets too narrow, it does not work :(
</div>
</div>
</div>
</div>