Making Embedded Content Work In A Responsive iFrame

You have an iframe:

<iframe src="https://www.youtube.com/embed/wnJ6LuUFpMo" frameborder="0" gesture="media" allowfullscreen></iframe>

It’s not responsible. Put a div around it:

<div class="video-container">
<iframe src="https://www.youtube.com/embed/wnJ6LuUFpMo" frameborder="0" gesture="media" allowfullscreen></iframe>
</iframe>
</div>

Now format the div by adding this css:

.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 35px;
height: 0;
overflow: hidden;
}

.video-container iframe {
position: absolute;
top:0;
left: 0;
width: 100%;
height: 100%;
}

Result: the iframe is now responsive, sort of. See:

Source: Making Embedded Content Work In A Responsive iFrame

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.