Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a responsive Youtube embed iframe with Twitter Bootstrap?

Currently I'm embedding Youtube videos with the following HAML code in a Twitter Bootstrap based site:

.row   .span12     %iframe.span11{ :height => "720", :frameborder => "0", :allowfullscreen => nil, :src => v.video_url } 

Unfortunately, this doesn't respond well when resizing the browser or on mobile devices because of the static height.

What would be a better (more dynamic and responsive) way to implement this embedded iframe for Youtube?

like image 442
Peter Giacomo Lombardo Avatar asked Aug 28 '12 20:08

Peter Giacomo Lombardo


People also ask

How do you make an embedded YouTube video responsive HTML?

You will need to wrap the responsive youtube embed code with a div and specify a 50% to 60% padding bottom. Then specify the child elements (iframe, object embed) 100% width, 100% height, with absolute position. This will force the embed elements to expand fullwidth automatically. Awesome!


1 Answers

Try this "Responsive video CSS", it works perfect for me: https://gist.github.com/2302238

<section class="row">   <div class="span6">     <div class="flex-video widescreen"><iframe src="https://www.youtube-nocookie.com/embed/..." frameborder="0" allowfullscreen=""></iframe></div>   </div>   <div class="span6">     ...   </div> </section> 
like image 176
Bart Naus Avatar answered Oct 06 '22 13:10

Bart Naus