Full-screen iframe with a height of 100%

前端 未结 17 1150
星月不相逢
星月不相逢 2020-11-22 04:35

Is iframe height=100% supported in all browsers?

I am using doctype as:



        
相关标签:
17条回答
  • 2020-11-22 05:22

    This worked very nicely for me (only if iframe content comes from the same domain):

    <script type="text/javascript">
    function calcHeight(iframeElement){
        var the_height=  iframeElement.contentWindow.document.body.scrollHeight;
        iframeElement.height=  the_height;
    }
    </script>
    <iframe src="./page.html" onLoad="calcHeight(this);" frameborder="0" scrolling="no" id="the_iframe" width="100%" ></iframe>
    
    0 讨论(0)
  • 2020-11-22 05:23

    Another way to build fluid full screen iframe:


    Embedded video fills entire viewport area when page loads

    Nice approach for landing pages with video or any embedded content. You can have any additional content below of embedded video, which is revealed when scrolling page down.

    Example:

    CSS and HTML code.

    body {
        margin: 0;
        background-color: #E1E1E1;
    }
    header {
        width: 100%;
        height: 56vw;
        max-height: 100vh;
    }
    .embwrap {
        width: 100%;
        height: 100%;
        display: table;
    }
    .embwrap .embcell {
        width: auto;
        background-color: black;
        display: table-cell;
        vertical-align: top;
    }
    .embwrap .embcell .ifrwrap {
        height: 100%;
        width: 100%;
        display: inline-table;
        background-color: black;
    }
    
    .embwrap .embcell .ifrwrap iframe {
        height: 100%;
        width: 100%;
    }
    <header>
      <div class="embwrap">
        <div class="embcell">
          <div class="ifrwrap">
            <iframe webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen="true" allowtransparency="true" scrolling="no" frameborder="0" width="1920" height="1440" src="http://www.youtube.com/embed/5SIgYp3XTMk?autoplay=0&amp;modestbranding=1&amp;iv_load_policy=3&amp;showsearch=0&amp;rel=1&amp;controls=1&amp;showinfo=1&amp;fs=1"></iframe>
          </div>
        </div>
      </div>
    </header>
    <article>
      <div style="margin:30px; text-align: justify;">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis lorem orci, rhoncus ut tellus non, pharetra consequat risus. </p>
        <p>Mauris aliquet egestas odio, sit amet sagittis tellus scelerisque in. Fusce in mauris vel turpis ornare placerat non vel purus. Sed in lobortis </p>
      </div>
    </article>

    0 讨论(0)
  • 2020-11-22 05:27
    <iframe src="http://youraddress.com" style="width: 100%; height: 100vh;">
    
    </iframe>
    
    0 讨论(0)
  • 2020-11-22 05:27

    http://embedresponsively.com/

    This is a great resource and has worked very well, the few times I've used it. Creates the following code....

    <style>
    .embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; } 
    .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
    </style>
    <div class='embed-container'>
    <iframe src='http://player.vimeo.com/video/66140585' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
    </div>
    
    0 讨论(0)
  • 2020-11-22 05:30

    body {
        margin: 0;            /* Reset default margin */
    }
    iframe {
        display: block;       /* iframes are inline by default */
        background: #000;
        border: none;         /* Reset default border */
        height: 100vh;        /* Viewport-relative units */
        width: 100vw;
    }
    <iframe></iframe>

    0 讨论(0)
提交回复
热议问题