I have an iframe and I need the height of it to be automatic according to the content inside it. How can I do this? No jquery of preference.
I have an iframe and I need the height of it to be automatic according to the content inside it. How can I do this? No jquery of preference.
Unfortunately, you can not leave the iframe with automatic height according to content.
The only way to solve the problem is to implement a Javascript within the iframe that sends the height of the body (from within the iframe) out of the iframe via postMessage. Receiving height, you resize the iframe.
The link below has an explanation of how to do this:
Create a class and assign the 'height: auto' property, if you wanted to limit a max size you can use max-height: ''.
Html
<iframe class="frame"></iframe>
Css
.frame{height:auto;max-heignt:100px;}
You need to set in the body and html tag height value: 100%, following example:
body, html {
height:100%;
}
iframe {
height:100%;
width:100%;
background:cyan;
}
<iframe></iframe