Let's say I have a video with a known aspect ratio. I need to make it act like a fixed background-cover for a full-screen section (100vw / 100vh).
But also I need to attach some floating absolute-positioned elements, relative to the content of the video. For example, 60% left / 40% top point relative to the content of the video .
So If I use object-fit: cover on the video, and position: absolute for the floating elements, I can no longer just provide left / top percentage offset, because those percents no longer match the content of the video.
I tried to overcome this problem by using some math formulas like:
--video-aspect-ratio: 1680 / 944;
--video-height: max(100vh, 100vh / var(--video-aspect-ratio));
--video-width: max(100vw, 100vw * var(--video-aspect-ratio));
--vertical-video-offset: min(0%, (100vh - var(--video-height)) / 2);
--horizontal-video-offset: min(0%, (100vw - var(--video-width)) / 2);
position: absolute;
inset: var(--vertical-video-offset) var(--horizontal-video-offset);
But it just doesn't seems to work for some reason.
Need some help in figuring out how to achieve this layout, preferably in plain CSS.
Any ideas? Thanks!