How can I create a 100vw background video using a Vimeo embed, with a height that scales proportionally at 100%?
I’m taking the code from Vimeo’s Background Video article and I’ve found this tutorial that does a good job of explaining how to implement a video that’s 100vw and 100vh. However, I don’t want the latter.
I can very easily create this with the Video element and my Vimeo link (see this page of mine), but I need the embed so all controls are removed and it autoplays. The Vimeo embed doesn’t seem to react to styling for some reason unless it’s 100vw and 100vh. Super frustrating. Can anyone help?
display set to flex with align center and justify center
position set to relative
overflow set to hidden
Inside of that section put a video wrapper div
height: 100%
position: absolute (Auto all around)
width: 1000% (yes, one thousand) It can be less but this ensures it will be responsive on all screen sizes. Because this div is centered by the parent flexbox, it will stay centered even though the width is huge. Be sure to set the parent div overflow to hidden so this doesn’t move.
Inside of that div, I have an HTML embed element
position: absolute (full)
width: 100%
height: 100%
insert the iframe code from Vimeo and set the inline height to 100% and width to 100%
Does it appear that way when you view the project in the Read-only link or Clone link above? Or are you trying to use a Youtube link? This method only works with Vimeo.
Thank you so so much for taking the time to write this up and share the clonable. I’ve searched for days for such a clean answer.
Great tip with the 56.25% padding @carlos_av
This worked great on desktop - thank you so much! Displaying well on mobile, however, video is always blurry and cannot figure out why. Video has no problem loading and playing on desktop with the same internet connection as the phone. Would you happen to have any idea? Thank you in advance!