html - How to make responsive iframe when there are multiple iframes -


this works great, until have 2 or more iframes in same container, overlap each other because both have same absolute position.

how allow arbitrary number of iframes inside of container built house iframes , maintain aspect ratios?


from: https://www.h3xed.com/web-development/how-to-make-a-responsive-100-width-youtube-iframe-embed

the key creating responsive youtube embed padding , container element, allows give fixed aspect ratio. can use technique other iframe-based embeds, such slideshows.

here typical youtube embed code looks like, fixed width , height:

<iframe width="560" height="315" src="//www.youtube.com/embed/ycoy82udfrw"  frameborder="0" allowfullscreen></iframe> 

it nice if give 100% width, won't work height remains fixed. need wrap in container (note class names , removal of width , height):

<div class="container"> <iframe src="//www.youtube.com/embed/ycoy82udfrw"  frameborder="0" allowfullscreen class="video"></iframe> </div> 

and use following css:

.container {     position: relative;     width: 100%;     height: 0;     padding-bottom: 56.25%; } .video {     position: absolute;     top: 0;     left: 0;     width: 100%;     height: 100%; } 

don't put 2 videos in same container. put 2 containers , wrap them in single wrapper. change width , bottom-padding whatever want.

.container {      position: relative;      width: 50%;      height: 0;      padding-bottom: 28.13%;      display:inline-block;      margin:0;  }  .video {      position: absolute;      top: 0;      left: 0;      width: 100%;      height: 100%;  }
<div class="wrapper">    <div class="container">      <iframe src="//www.youtube.com/embed/3sdes6qupro" frameborder="0" class="video"></iframe>    </div><div class="container">      <iframe src="//www.youtube.com/embed/ycoy82udfrw" frameborder="0" class="video"></iframe>    </div>  </div>


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -