Home  >  Article  >  Web Front-end  >  How to Control iframe Size on iOS with CSS?

How to Control iframe Size on iOS with CSS?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-25 12:36:30553browse

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>

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!

Statement:
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