darkchampionz
darkchampionz

Reputation: 1234

HTML/CSS - Iframe fit screen

I use the code below in order to display a youtube video. I set its size at 560 width and 315 height. Code works good but when I try to resize the window, the iframe/video doesn't resize but instead scrollbars appear. How can I make the iframe also resize so it always fits the width of the screen?

<body>
    <iframe width="560" height="315" src="https://www.youtube.com/embed/a3ICNMQW7Ok?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
</body>

Upvotes: 1

Views: 3747

Answers (2)

Responsive With Device iframe

.container {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%;
}
.video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
<body>

<div class="container">
<iframe src="https://www.youtube.com/embed/a3ICNMQW7Ok?rel=0&amp;showinfo=0" 
frameborder="0" allowfullscreen  scrolling="auto" class="video"></iframe>
</div>

</body>

Upvotes: 2

pavithra
pavithra

Reputation: 336

the given width and heights are fixed sizes. if you give them in percentage like 70%,80% it should resize with the window

 <body>
        <iframe width="100%" height="500px" src="https://www.youtube.com/embed/a3ICNMQW7Ok?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
    </body>

Upvotes: 2

Related Questions