Default width/height of an IFrame

前端 未结 2 1423
说谎
说谎 2020-12-05 06:32

Is there any spec specifying the default width/height of an IFrame?

Browsers I tested (FF, IE, Chrome) seem to use 300x150px but I couldn\'t find any spec on this.

相关标签:
2条回答
  • 2020-12-05 06:57

    I would set the width and height explicitly to ensure consistent rendering across multiple browsers/platforms as there is no guarantee that every browser will implement the same default dimensions.

    <iframe src="iframePage.html" width="100%" height="300">
      <p>Your browser does not support iframes.</p>
    </iframe>
    
    0 讨论(0)
  • 2020-12-05 07:04

    I found the answer on the dev-tech-layout mailing list -- it's part of the CSS spec. The default ratio is 2:1.

    The default width of 300px is defined in the last paragraph of the CSS spec, section on the width of inline replaced elements.

    Otherwise, if 'width' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'width' becomes 300px. If 300px is too wide to fit the device, UAs should use the width of the largest rectangle that has a 2:1 ratio and fits the device instead.

    The default height of 150px is defined in the last paragraph of the CSS spec, section on the height of inline replaced elements.

    Otherwise, if 'height' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'height' must be set to the height of the largest rectangle that has a 2:1 ratio, has a height not greater than 150px, and has a width not greater than the device width.

    0 讨论(0)
提交回复
热议问题