Device-Bugs icon indicating copy to clipboard operation
Device-Bugs copied to clipboard

iOS iFrame element dimensions can not be constrained

Open scottjehl opened this issue 12 years ago • 6 comments

Summary:

iOS doesn't respect width or height on an iframe via CSS or any other means. It always sizes the iframe to the child document height. This is generally a good feature, but it can cause confusion if you're doing something where you expect this to work.

Platforms:

  • iOS 5 and older Safari

How to reproduce:

  1. style an iframe with dimensions smaller than its document
  2. open it in ios Safari

Reduced Example:

http://jsbin.com/olobaw

Bug Tracker ticket(s):

Workarounds:

scottjehl avatar Mar 26 '12 06:03 scottjehl

Add width: 1px; min-width: 100% and scrolling="no". This may also work with height but I did not test it.

Workaround test case: https://jsbin.com/gupabi/

Screenshots below are on an iPhone 6 using iOS9.

Before, using <iframe> image

After, using <iframe style="width: 1px; min-width: 100%;" scrolling="no"> image

zachleat avatar Jan 15 '16 15:01 zachleat

@zachleat If we have to sacrifice scrolling, then a more “standard” approach (that seems to work on iOS) would be absolute positioning + overflow: hidden on the parent <div>: https://jsbin.com/fuxonas/edit?html,css,output

simevidas avatar Jan 16 '16 06:01 simevidas

@simevidas Unfortunately that doesn’t quite work, the iframe doesn’t respect the width property: image

zachleat avatar Jan 16 '16 15:01 zachleat

@zachleat where you able to fix the problem with the width on the Iframe? I'm testing on IOS10 and I see the same problem with iframes

cesar-oyarzun-m avatar Oct 03 '16 18:10 cesar-oyarzun-m

@cesar-oyarzun-m: The min-width trick above seemed to work ok for fluid width iframes.

zachleat avatar Oct 04 '16 17:10 zachleat

@zachleat the problem that I have is that I have an image inside the iframe, but the image width is bigger then the iframe, so the iframe overflow, I just want the image to take the same width that the iframe, I don't want the iframe to overflow. Seems that the content inside the iframe doesn't respect the iframe size, I have set the iframe width=100% and height=100%

cesar-oyarzun-m avatar Oct 04 '16 17:10 cesar-oyarzun-m