No replies
jkruby's picture
1218 Geranium Avenue
Last seen: 4 weeks 3 days ago
1218 Geranium Avenue
Timezone: GMT-4
Joined: 2022-05-10
Posts: 1
Points: 2

I have been trying to produce, within a WordPress website, a nearly full screen iframe whose size will adjust to the content of the iframe document. I have seen numerous JavaScript solutions that query the DOM of the iframe, but I cannot do that because of Cross Origin restrictions.

I found a CSS hack online that works really well on all resolutions except for phones in portrait mode. Here is the code. You can see it in action at .

.resp-container {
    position: relative;
    overflow: hidden;
    padding-top: 56.25%; 
.resp-iframe {
    position: absolute;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    top: 0;
    left: 0; 
    width: 100%;
    height: 100%;
    border: 0;
<div class="resp-container" >
    <iframe id="free_iframe" class="resp-iframe" src="" allow="autoplay" allowfullscreen></iframe>

The issue occurs after a search is run and the results display. In Phone Portrait the results are not visible because the height of the iframe becomes so short that they do not appear.
I probably need to add @media queries but I have not found the right CSS to make it display on phone in portrait mode. Any help would be appreciated. I have read that the padding-top: 56.25% is related to the Width of the container even though it is a vertical padding? That doesn't make much sense to me. I tried padding-top of 10%^ and 90% and it doesn't seem to work. Can anyone recommend the CSS to use for Mobile Portrait orientation in this case?

Thank you

Iframe-good-display.jpg115.61 KB
Iframe-too-short-display.jpg38.59 KB