0

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
Community
  • 1
  • 1
SparkAndShine
  • 17,001
  • 22
  • 90
  • 134
  • 1
    It seems to be working fine with a youtube video - https://jsfiddle.net/eo8fwwjs/ – Stickers Feb 27 '17 at 21:57
  • @Pangloss, yup, it works after clearing caches in my machine. Do you have ideas to make them work for different aspect ratios? – SparkAndShine Feb 27 '17 at 22:01
  • It's not clear what you're asking. Aspect ratios of what? Based on what condition? – isherwood Feb 27 '17 at 22:02
  • 1
    You just need to use different classes, e.g. `.intrinsic-container-16x9 {padding-bottom:56.25%;}` and `.intrinsic-container-4x3 {padding-bottom:75%;}` etc. – Stickers Feb 27 '17 at 22:05
  • @Pangloss, thx for ur constant help. If I embed a video with `4:3`, which one should I use, `
    ` or `
    `?
    – SparkAndShine Feb 27 '17 at 22:38
  • That would be `4x3`, you can assign both classes if you want it's up to how you want to organize the style. – Stickers Feb 27 '17 at 22:48

0 Answers0