Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap responsive iframe not resize

I am developing a responsive web page using bootstrap framework, and I want to put a responsive iframe.

The bootstrap docs says that I can put a responsive 16x9 aspect ratio iframe using

<div class="embed-responsive embed-responsive-16by9">
  <iframe class="embed-responsive-item" src="…"></iframe>
</div>

and the css (included in the bootstrap.css) is

.embed-responsive
{
display: block;
height: 0;
overflow: hidden;
position: relative;
}

.embed-responsive.embed-responsive-16by9
{
padding-bottom: 56.25%
}

.embed-responsive .embed-responsive-item, .embed-responsive iframe, .embed-responsive embed, .embed-responsive object
{
border: 0 none;
bottom: 0;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}

The result is that the container of the iframe (the div with class "embed-responsive...") is responsive. This takes the correct width and height according to the resolution. But the iframe is overflowed, because it is not resized.

How can I do to resize the iframe to exactly fill the div?

like image 355
Josecanalla Avatar asked Jul 17 '14 21:07

Josecanalla


People also ask

Can iFrames be made responsive?

A responsive iframe will render well across a variety of devices and screen sizes. In order to make your embedded iframe responsive, you need to wrap the iframe in a div and apply inline css. Follow these simple steps: Get the iframe embed code and paste in into your HTML page.

Can iframe be resized?

iFrames let you embed external content, such as YouTube videos, advertisements, and content from other sites into your own web page. You can easily resize iFrames using HTML and/or CSS, and even make them resizable so they'll adjust automatically based on the user's screen size.

Which of the following aspect ratio is used with responsive video?

The width & height of the playere determines the aspect ratio. We recommend an aspect ratio of 16:9.

Does iframe work on mobile?

Embedding project via iframe does not work on tablet or smartphone – InVision Support.


2 Answers

I was having this problem too. I found a somewhat hack solution. In the iframe section: width:100% so it should look like:

<iframe class="embed-responsive-item" src="…" width="100%"></iframe>

I had to set a fixed value for my height because the iframe source isn't responsive.

Hope that helps.

like image 165
spasticninja Avatar answered Sep 17 '22 21:09

spasticninja


You can use boostrap for this, but it's such a simple task that you really don't need any framework to help you with this. Check out Responsive Iframes; it's not using any frameworks, and is written in native javascript.

like image 44
Taylor Daughtry Avatar answered Sep 17 '22 21:09

Taylor Daughtry