Balasubramani R
Balasubramani R

Reputation: 7

IFrame Responsive issue

How to make the iframe in responsive with full width

iframe {position:absolute;top:0;left:0;width:100%; height:100%;}
iframe, object, embed {
    max-width: 100%;
}

This is my code but not working

Note:

If we have used height in pixels(IFRAME Tag) then comes correctly in full width. But not working in responsive

what is the solution?

Upvotes: 0

Views: 105

Answers (1)

willcaddy
willcaddy

Reputation: 33

I think this is what you are looking for. I assume that you are using YouTube so just paste in the embed link where the other link is.

HTML

<div class="videoWrapper">
    <!-- Copy & Pasted from YouTube -->
    <iframe width="560" height="349" src="http://www.youtube.com/embed/n_dZNLr2cME?rel=0&hd=1" frameborder="0" allowfullscreen></iframe>
</div>

CSS

.videoWrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 25px;
    height: 0;
}
.videoWrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

I used this guide: https://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php

I used the same method for my own website and it works great. Hope this helps you out!

Upvotes: 1

Related Questions