How to Control iframe Size on iOS with CSS?

Mary-Kate Olsen
Release: 2024-10-25 12:36:30
Original
563 people have browsed it

How to Control iframe Size on iOS with CSS?

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!