Edge doesn't stretch iframe in a flexbox

拥有回忆 提交于 2019-12-05 23:25:28

问题


The iframe in the following demo is a flex item:

* {
  margin: 0;
  border: 0;
  padding: 0;
}
html,
body {
  height: 100%;
}
body {
  display: flex;
}
iframe {
  background: olive;
  flex: 1;
}
<iframe></iframe>

But it doesn't cover the flex container:

If you replace iframe with a div, it works with no problem.

  1. Why is that?
  2. What's the right approach to resolve the issue?

回答1:


There does appear to be an interop issue between Microsoft Edge, and Chrome/Firefox. I'll file a bug on this immediately after answering this question, and have the team investigate further.

My immediate suggestion would be to add a <div> around the <iframe>, flex that <div>, and then set the width and height of the <iframe> to 100%. I set out to do this, when I noticed Chrome appears to not size the iframe like Firefox and Microsoft Edge do.

I did find success with the following approach:

<body>
    <div>
        <iframe src="http://bing.com"></iframe>
    </div>
    <div>
        <p>Flex item number 2</p>
    </div>
</body>
html, body, div, iframe {
  border: 0; padding: 0; margin: 0;
}

html, body {
  height: 100%;
}

body {
  display: flex;
}

div {
  flex: 1;
  position: relative;
}

iframe {
  position: absolute;
  width: 100%; height: 100%;
}

Results: http://jsfiddle.net/jonathansampson/o7bvefy1/




回答2:


The solution is to add min-height: 100%; to the iframe.

* {
  margin: 0;
  border: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  display: flex;
}

iframe {
  background: olive;
  flex: 1;
  min-height: 100%;
}
<iframe></iframe>


来源:https://stackoverflow.com/questions/34095170/edge-doesnt-stretch-iframe-in-a-flexbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!