Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iframe size with CSS on iOS

There's an iframe, which basically has more content than fits into the frame. The sizing of the frame is based on the browser screen size and lets the overflow scroll, which works perfectly on all browsers, except for iOS. On iOS, safari decides to resize the frame to fit the content. Not what you'd expect.

Example code on jsFiddle:
http://jsfiddle.net/R3PKB/2/

Try it out on your iOS devices:
http://jsfiddle.net/R3PKB/2/embedded/result

The HTML:

<div class="frame_holder">   <iframe class="my_frame">     // The content   </iframe> </div> 

The CSS:

body {   position: relative;   background: #f0f0f0; }  .frame_holder {   position: absolute;   top: 50px;   bottom: 50px;   left: 50px;   right: 50px;   background: #ffffff; }  .my_frame {   width: 100%;   height: 100%;   border: 1px solid #e0e0e0; } 
like image 772
Guido Bouman Avatar asked Jun 05 '13 10:06

Guido Bouman


People also ask

How do I make an iframe bigger in CSS?

Edit the height attribute. For example, if you enter the attribute "height: 100%;", this will tell the iframe to use 100% of the vertical space available. You can also enter "height: auto;" to automatically adjust the height relative to the width. If there is no height attribute, go ahead and add one.

How do I make my iframe height 100%?

Next, we put the <iframe> inside this box, making it fill the whole box. To size the <iframe> , we ignore the width="560" height="315" element properties, and instead use the CSS properties width:100%;height:100%; . That's it: a full-width <iframe> with fixed aspect ratio. Enjoy.

Does iframe work on iPad?

iframes used to be scrollable on the iPad using two fingers. This functionality was removed in an update a few months ago. iframes don't respect overflow on iPad, and require an additional container surrounding the iframe with overflow:hidden.

Does Safari support iframes?

See full reference on MDN Web Docs. 1 Safari has a bug that prevents iframes from loading if the iframe element was hidden when added to the page.


2 Answers

You can make it work by adding a wrapping div with overflow: auto; and -webkit-overflow-scrolling:touch;. Here's your example with it: http://jsfiddle.net/R3PKB/7/

According to previous questions on SO it's a bug since iOS 4. I found more info here: https://stackoverflow.com/a/6721310/1047398 iframe on iOS (iPad) content cropping issue

like image 115
nvreez Avatar answered Sep 30 '22 06:09

nvreez


This is an old question, but since it comes first on google and the issue exists on nowadays ios devices, I repost a better fix that I found on this page: How to get an IFrame to be responsive in iOS Safari?

Basically, if you have an iframe with scroll (let's say a twitter widget), the solution above won't work very well because it makes the parent scrollable. The fix that worked for me is replacing height: 100% with height: 1px; min-height: 100%;.

like image 35
Andrei Cojea Avatar answered Sep 30 '22 06:09

Andrei Cojea