Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making an iframe resize according to the window size

Tags:

html

iframe

I'd like to make the size of the video relative to the screen size. However, if I set the height as fixed, on some screen sizes it does not work. Any way I can get the video to fit the screen, but not be out of proportion?

The full code is here: https://github.com/GiacomoLaw/british-airways-virtual/blob/master/index.html

Thank you!

like image 824
Giacomo Avatar asked Dec 21 '25 20:12

Giacomo


1 Answers

Wrap the video in another element which has an intrinsic aspect ratio, then absolute position the video within that. That gives us fluid width with a reasonable height we can count on.

<div class="videoWrapper">
<iframe src='https://www.liveflightapp.com/embed?key=b1371aa1-dea8-41cd-af74-8fda634b3a5d' width='100%;' height='500px;' frameborder='0' scrolling='no'></iframe>
</div>

And then apply the following style properties..

.videoWrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 25px;
    height: 0;
}
.videoWrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

May be that helps..

like image 53
Gaurav Gupta Avatar answered Dec 24 '25 11:12

Gaurav Gupta