How can I make the YouTube player scale to the width of the page but also keep the aspect ratio?

后端 未结 14 1955
一向
一向 2021-01-30 11:09

I have a YouTube video I want to put on my web page.

I want to scale the video to fit to a percent of the users browser but also to keep the aspect ratio.

I hav

14条回答
  •  长发绾君心
    2021-01-30 11:29

    What i believe to be the best CSS solution.

    .auto-resizable-iframe {
      max-width: 420px;
      margin: 0px auto;
    }
    
    .auto-resizable-iframe > div {
      position: relative;
      padding-bottom: 75%;
      height: 0px;
    }
    
    .auto-resizable-iframe iframe {
      position: absolute;
      top: 0px;
      left: 0px;
      width: 100%;
      height: 100%;
    }
    

    Demo http://jsfiddle.net/JBhp2/

提交回复
热议问题