Responsive iframe for different aspect ratio

2019-06-09 13:48发布

问题:

I followed this post Making an iframe responsive to make iframes responsive.

# A test case
<div class="intrinsic-container">
    <iframe frameborder="0" width="640" height="498" src="https://v.qq.com/iframe/player.html?vid=y0379t92gl9&tiny=0&auto=0" allowfullscreen></iframe>
</div>

# style.css
.intrinsic-container {
    position: relative;
    /* padding-bottom: 56.25%; /* 16:9 */
    padding-bottom:75%; /* 4:3 */
    /* padding-bottom: 66.66%; /* 3:2 */
    /* padding-top: 25px; */
    height: 0;
}

.intrinsic-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

It works. My question is how to make iframes responsive for different aspect ratios of content areas, such as

  • YouTube video: width="560" height="315", the ratio is 16:9
  • width="640" height="498", the ratio is 4:3