I now have browsed through a whole bunch of threads here on this topic, but all I can find is how to solve this issue on full screen. So.. how do I embed a Vimeo video iframe in a container with arbitrary size (not full size!), so it behaves like CSS background-size:cover. So basically that it overflows either Y or X. I also want to center the video in the container.
Here is my code:
<figure class="video-background ">
<iframe src="https://player.vimeo.com/video/364558071?background=1&api=1&loop=1&title=0&byline=0&portrait=0&autoplay=1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</figure>
My video-background div has a fixed height of 400px and a fluid width
This answer from Oliver shows how to do it on full-screen, but how do I mimic this behavior on a smaller div ? His solution looks like this:
.video-background {
position: relative;
overflow: hidden;
width: 100vw;
height: 100vh;
}
.video-background iframe {
position: absolute;
top: 50%;
left: 50%;
width: 100vw;
height: 100vh;
transform: translate(-50%, -50%);
}
@media (min-aspect-ratio: 16/9) {
.video-background iframe {
/* height = 100 * (9 / 16) = 56.25 */
height: 56.25vw;
}
}
@media (max-aspect-ratio: 16/9) {
.video-background iframe {
/* width = 100 / (9 / 16) = 177.777777 */
width: 177.78vh;
}
}
Hope you can help! Thanks!