How to prevent Iframe video go beyond max-width & max-height?

喜欢而已 提交于 2019-12-13 01:45:55

问题


I embedded a responsive youtube video with bootstrap.

My aim: keep it's max size width="560" height="315" which is then centered.

How it should be: https://avexdesigns.com/responsive-youtube-embed/

But instead it goes beyond these limits, making the video very blurry.

How it should not be: https://bomengeduld.github.io/mos-man2/

So far I tryed to set max-width & max-height in css, but it only adjusts the width.

What Am I Doing Wrong in this Code? Thank you in advance for clearing this up!


回答1:


If understood it correctly you want something like this:

#embed {
    height: auto;

    text-align: center;
    background: black;
    width: 100%; /* new */
    max-width: 560px; /* new */
    margin: 0 auto; /* new */
}


.videowrapper {
    float: none;
    clear: both;
    width: 100%;
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 25px;
    height: 0;
}

.videowrapper iframe, .videowrapper object, .videowrapper embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}
<section id="embed">


                  <div class="container-fluid videowrapper">

                  <iframe src="https://www.youtube.com/embed/g42lHnzOeVs" width="560" height="315" frameborder="0" allowfullscreen=""></iframe>
                  </div>


</section>


来源:https://stackoverflow.com/questions/44249106/how-to-prevent-iframe-video-go-beyond-max-width-max-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!