I am trying to integrate a YouTube video using their embed code in a "pop-up". However, I am facing an issue where the video does not resize to fit within the height of its parent. I want it to be constrained by the div#pop-up that contains the video. Currently, the video will stretch as wide as possible and maintain its aspect ratio for height even if it exceeds the parent's height. My goal is for the video to fill the parent's padding or margin while staying centered and maintaining a 16:9 aspect ratio.
I would prefer not to use jQuery, so JavaScript might be a suitable option.
*{
margin:0;
padding:0;
}
#pop-up{
width:100%;
height:100vh;
padding:5%;
box-sizing: border-box;
background:rgba(0,0,0,0.2);
}
<div id="pop-up">
<!--Youtube embed code-->
<div style="position:relative;height:0;padding-bottom:56.25%"><iframe src="https://www.youtube.com/embed/ZLtNZuQzJ4w?ecver=2" width="640" height="360" frameborder="0" style="position:absolute;width:100%;height:100%;left:0" allowfullscreen></iframe></div>
</div>
Here's a visual example of what I'm aiming for:
If the browser is wide like a computer or landscape phone: https://i.sstatic.net/FsBWC.jpg
If the browser is tall like a portrait phone or tablet:https://i.sstatic.net/M7HgM.jpg