How to prevent Iframe video go beyond max-width &

2019-07-31 07:19发布

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条回答
做个烂人
2楼-- · 2019-07-31 08:03

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>

查看更多
登录 后发表回答