As well as to the body of the iframe (via a plugin in my backend).
The problem that I have is that the iframe can be different heights, depending on what content it must display.
What I’d like to know - is it possible to have the iframe take up 100% of the available width (so that it’s responsive) and just as much height as it needs to display its contents? As things stand I have to set the height to the maximum it can be (when displaying a long message). If it displays a short message, then there is an unsightly gap between the iframe and the nearest contents below it.
Here’s a small demo to demonstrate the problem. You can change the contents of the iframe by turning on/off the “Do Not Track” settings of your browser. (See here: https://allaboutdnt.com/)
Regardless of what the contents of the iframe are, I’d like it to occupy 100% width and just enough height to display its contents, without a large gap to the proceeding <p> tag.
Hello Pullo,
Yes it’s possible, there is a little trick that sets a bottom padding on the iframe parent div. That padding is based on the aspect ratio of the iframe and it controls the scaling.
Here is a shot with inspector on the iframe <body> with it’s fluid height of the actual content.
And as you say that height could change, so there won’t be any scaling of the iframe in this situation.
Thank you for the in-depth reply. I tried following the tutorial you linked to (in the second post) but couldn’t get it to work at all, so thanks for the sanity check, too
I can certainly do this. Could you point me in the direction of which styles I might need to apply to the iframe body? I can set a height in pixels or % but that doesn’t really help (as far as I can see).
but nothing was included in the page - it failed silently.
The page whose contents I’m trying to include exists (as you can verify), so is it possible that my shared hosting blocks file_get_contents (and if so, how can I test that)?