[html] Make Iframe to fit 100% of container's remaining height

Here are a few modern approaches:


  • Approach 1 - Combination of viewport relative units / calc().

    The expression calc(100vh - 30px) represents the remaining height. Where 100vh is the height of the browser and the usage of calc() effectively displaces the height of the other element.

    Example Here

    _x000D_
    _x000D_
    body {_x000D_
        margin: 0;_x000D_
    }_x000D_
    .banner {_x000D_
        background: #f00;_x000D_
        height: 30px;_x000D_
    }_x000D_
    iframe {_x000D_
        display: block;_x000D_
        background: #000;_x000D_
        border: none;_x000D_
        height: calc(100vh - 30px);_x000D_
        width: 100%;_x000D_
    }
    _x000D_
    <div class="banner"></div>_x000D_
    <iframe></iframe>
    _x000D_
    _x000D_
    _x000D_

    Support for calc() here; support for viewport relative units here.


  • Approach 2 - Flexbox approach

    Example Here

    Set the display of the common parent element to flex, along with flex-direction: column (assuming you want the elements to stack on top of each other). Then set flex-grow: 1 on the child iframe element in order for it to fill the remaining space.

    _x000D_
    _x000D_
    body {_x000D_
        margin: 0;_x000D_
    }_x000D_
    .parent {_x000D_
        display: flex;_x000D_
        flex-direction: column;_x000D_
        min-height: 100vh;_x000D_
    }_x000D_
    .parent .banner {_x000D_
        background: #f00;_x000D_
        width: 100%;_x000D_
        height: 30px;_x000D_
    }_x000D_
    .parent iframe {_x000D_
        background: #000;_x000D_
        border: none;_x000D_
        flex-grow: 1;_x000D_
    }
    _x000D_
    <div class="parent">_x000D_
        <div class="banner"></div>_x000D_
        <iframe></iframe>_x000D_
    </div>
    _x000D_
    _x000D_
    _x000D_

    Since this approach has less support1, I'd suggest going with the aforementioned approach.

1Though it seems to work in Chrome/FF, it doesn't work in IE (the first method works in all current browsers).

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to css

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width

Examples related to iframe

Getting all files in directory with ajax YouTube Autoplay not working Inserting the iframe into react component How to disable auto-play for local video in iframe iframe refuses to display iFrame onload JavaScript event YouTube iframe embed - full screen Change New Google Recaptcha (v2) Width load iframe in bootstrap modal Responsive iframe using Bootstrap