Scale iFrame css width 100% like an image

前端 未结 6 1460
悲&欢浪女
悲&欢浪女 2020-12-04 08:21

I want to scale an iFrame through CSS to width: 100%, and the height should scale proportionally to the width.

With an tag this

6条回答
  •  萌比男神i
    2020-12-04 08:59

    None of these solutions worked for me inside a Weebly "add your own html" box. Not sure what they are doing with their code. But I found this solution at https://benmarshall.me/responsive-iframes/ and it works perfectly.

    CSS

    .iframe-container {
      overflow: hidden;
      padding-top: 56.25%;
      position: relative;
    }
    
    .iframe-container iframe {
       border: 0;
       height: 100%;
       left: 0;
       position: absolute;
       top: 0;
       width: 100%;
    }
    
    /* 4x3 Aspect Ratio */
    .iframe-container-4x3 {
      padding-top: 75%;
    }
    

    HTML

提交回复
热议问题