Ever notice that when you shrink your browser width an embedded video doesn't always shrink with it? Or that the same video doesn't scale quite right on a mobile or tablet? We noticed the same thing when we rebuilt and launched a newer, much sexier ZURBlog this year. We wanted the blog to be 100% responsive, meaning it had to look sexy on any device. Figuring out how to properly scale video embeds was one of the hurdles we overcame.
Videos That Break Down
The problem is that we don't know which device the video embeds will be viewed on. Will someone open up our videos on a phone? On a tablet? On a laptop? We have no control on how people are going to consume our videos.
The standard embed works nice for desktops, but breaks down on phones and tablets. Here is an example: try to shrink your browser width smaller then this video below and you'll see how it's displayed on a smaller screen.
Making Videos Look Awesome On All Devices
The major issue with scaling is to ensure you keep the ratio of width to height constant and adjust the height appropriately. The code to embed a responsive video on your site is dead simple if you're using Foundation, here it is:
<div class="flex-video"> <iframe width="420" height="315" src="http://www.youtube.com/embed/9otNWTHOJi8" frameborder="0" allowfullscreen></iframe> </div> <div class="flex-video widescreen"> <iframe width="560" height="315" src="http://www.youtube.com/embed/N966cATFWjI" frameborder="0" allowfullscreen></iframe> </div> <div class="flex-video widescreen vimeo"> <iframe src="http://player.vimeo.com/video/21762736?title=0&byline=0&portrait=0" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> </div>
That's all! You dont need to worry about how videos are displayed on any device anymore. You can read the full documentation about this feature on the Foundation site and, of course, dig through the code to see how it's implemented. Enjoy!