javascript - How to make an iframe responsive full height and full width -
i'm embedding youtube/dailymotion videos , want make iframe responsive , full height , same height window :
i made responsive iframe not full height !
here code
<div class="video-container"> <iframe height="100%" width="100%" src="https://www.youtube.com/embed/7ipiybrlqzc" frameborder="0" allowfullscreen></iframe> </div>
css :
.video-container { position: relative; padding-bottom: 100%; height:100%; } .video-container iframe, .video-container object, .video-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; margin:0px; }
use viewport percentage lengths, vw
, vh
set height , width of iframe
. optionally, use calc
subtract 4px
player seems add this.
viewport-percentage lengths defined length relatively size of viewport, visible portion of document. gecko-based browsers updating viewport values dynamically, when size of viewport modified (by modifying size of window on desktop computer or turning device on phone or tablet).
body { margin: 0; } iframe { height:calc(100vh - 4px); width:calc(100vw - 4px); box-sizing: border-box; }
<iframe src="https://www.youtube.com/embed/7ipiybrlqzc" frameborder="0" allowfullscreen></iframe>
Comments
Post a Comment