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?
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.
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.
The width & height of the playere determines the aspect ratio. We recommend an aspect ratio of 16:9.
Embedding project via iframe does not work on tablet or smartphone – InVision Support.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With