If you want to dynamically scale the size of a video based on the size of its wrapping div, you can utilize two classes. Take a look at this sample code:
<div class="content-holder">
<div class="video-holder aspect-16by9">
<iframe src="https://www.youtube.com/embed/pHsYFURtzzY" frameborder="0" allowfullscreen></iframe>
</div>
</div>
Now, let's delve into the CSS styling:
.content-holder{
max-width: 800px;
margin: 0 auto;
background-color: #fff;
}
.video-holder{
width: 100%;
position: relative;
}
.aspect-4by3{
padding-bottom: 75%;
}
.aspect-16by9{
padding-bottom: 56.25%;
}
.video-holder iframe{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Remember to enclose the iframe within a div with 100% width and relative position, and apply bottom padding to the wrapper to determine the video height. It's suggested to create classes for different aspect ratios.
You can easily calculate the padding percentage for specific aspect ratios. For instance, for 4:3 and 16:9 ratios:
[4:3 aspect]
100 / 4 * 3 = 75%;
[16:9 aspect]
100 / 16 * 9 = 56.25%
Position the iframe absolutely in the top left corner of the wrapping div, setting its width and height to 100%. This approach ensures proper scaling while maintaining aspect ratio.
Simply apply the appropriate class for the desired aspect ratio. This technique is versatile and can be used with various iframes, including Google Maps embeds.