iOS iframe Size Control with CSS
If you're using an iframe with content that exceeds its frame size, you may notice unexpected behavior on iOS. Unlike other browsers, Safari on iOS resizes the frame to accommodate the overflow content.
Consider the following HTML structure:
<code class="html"><div class="frame_holder"> <iframe class="my_frame"></iframe> </div></code>
And CSS:
<code class="css">.frame_holder { position: absolute; left: 50px; right: 50px; top: 50px; bottom: 50px; background: #ffffff; } .my_frame { width: 100%; height: 100%; border: 1px solid #e0e0e0; }</code>
On iOS, the iframe will resize to fit the content, ignoring the specified CSS height. To prevent this, one must add a wrapping div with the following CSS:
<code class="css">overflow: auto; -webkit-overflow-scrolling: touch;</code>
The updated HTML and CSS:
<code class="html"><div class="frame_holder"> <div style="overflow: auto; -webkit-overflow-scrolling: touch;"> <iframe class="my_frame"></iframe> </div> </div></code>
This solution adds an additional layer of control and forces the frame to adhere to the specified CSS dimensions, ensuring consistent behavior across all browsers.
The above is the detailed content of How to Control iframe Size on iOS with CSS?. For more information, please follow other related articles on the PHP Chinese website!