iOS WebKit iframe bug description
iOS WebKit resizes iframes to the full size of their content (see pic below). It's a bug known since 2016 and still not resolved in iOS 11: https://bugs.webkit.org/show_bug.cgi?id=155198
My current findings
1. For fixed iframe content (e.g. video)
It's enough to apply CSS below, but it prevents iframe content scrolling.
.fixed iframe {
width: 0;
height: 0;
min-width: 100%;
min-height: 100%;
}
2. For scrollable iframe content (e.g. pages)
- We need two iframe containers: one as a boundary (fixed size) and second one as a scrolling area.
- To fit iframe contents, its div container must have w/h defined in pixels. Any relative measures (like %, vw/vh) doesn't work.
Some RWD pages (let's say with "incomplete RWD") are experiencing iframe overflow (iframe does not fit into the iframe container). Unfortunately, we can't fix that from the iframe outside and to solve this issue, document inside iframe requires at least:
body { max-width: 100vw !important; }
Optionally, we can scale iframe content as a last resort.
Because of 2, to keep container proportion we need to use at least CSS media queries or JS to adjust its height.
Some incomplete solutions:
- https://github.com/ampproject/amphtml/issues/11133
- https://www.spacevatican.org/2015/4/7/on-mobile-safari-and-iframes/
- External HTML file in Bootstrap Popover content
- How to get an IFrame to be responsive in iOS Safari?
- iFrame Height Auto (CSS)
- Make iframe automatically adjust height according to the contents without using scrollbar?
- Iframe scrolling iOS 8
- iOS8 Safari -webkit-overflow-scrolling: touch; issue
My workaround is posted in answer.