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

后端 未结 14 1927
一向
一向 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:20

    Add JavaScript code to give each youtube iFrame a class:

    $('iframe[src*="youtube"]').addClass('youtube')
    

    Then in the Media Queries use the you tube class to set a different size.

    .youtube {
       /* Do stuff here */
    }
    

    Easier and optimized to CMS than the manual way.

提交回复
热议问题