I have a fullscreen youtube video embedded on my website.
It looks good when the size of the browser is proportional to the video’s width and height. However, when I resize the browser to a different proportion, I get black bars around the video.
What I want is to have the video fill the whole window at all times, but without any stretching. I want the “excess” to hide when the browser size is not proportional to the video.
What I am trying to achieve is something you can see in the background of these two websites: http://ginlane.com/ and http://www.variousways.com/.
Is it possible to do this with a youtube video?
I'm posting this because the answers above are for when you have the black bars at the top and at the bottom. What if you have the bars on the sides (left and right). This script will take care of the two scenario.
Create a container div around the iframe code and give it a class eg:
Add in the CSS:
This coolestguidesontheplanet.com is the Source URL of this answer.
Sadly this doesn't seem to be working.... Unless I am missing something: http://codepen.io/Archie22is/pen/EWWoEM
To simulate the same effect, the important thing is to maintain aspect ratio which is 16:9.
HTML
CSS
This will remove black bars.
Now we can set the outer container to 100% width and 100% height and hide the overflow.
Now the above code will work until viewport aspect ratio is greater than 16/9. So we have to add media query based on aspect ratio.
After this youtube video will maintain full viewport size at all condition and hide the extra part of a video. Other then opera it's supported in all the browser.
This is pretty old but people may still need help here. I needed this too so have created a Pen of my solution which should help - http://codepen.io/MikeMooreDev/pen/QEEPMv
The example shows two versions of the same video, one as standard and the second cropped and centrally aligned to fit the size of the full parent element without showing the hideous black bars.
You need to use some javascript to calculate a new width for the video but it's really easy if you know the aspect ratio.
HTML
CSS - The height and width o the videoWrapper can be anything, they can be percentages if you so wish
jQuery
This can also be triggered on resize to ensure it remains responsive. The easiest (probably not most efficient) way to do this is with the following.
You can also use this below:-