flex-grow isn't rendering correctly in Internet Explorer 11 (IE11)

て烟熏妆下的殇ゞ 提交于 2019-12-24 08:06:24

问题


I tried a new html design with flex boxes. The design in Chrome 58 Version 58.0.3029.110 is correct but not in IE11. I did not tried other browsers.

What is the issue?

body {
  display: flex;
  flex-flow: row wrap;
}

#left {
  flex: 6 0%;
  display: flex;
  flex-flow: row wrap;
}

#right {
  flex: 1 0%;
  background-color: black;
}

#top {
  flex: 1 100%;
  background-color: red;
}

#nav {
  flex: 1 0%;
  background-color: green;
}

#main {
  flex: 6 0%;
  background-color: blue;
}

#notepad {
  flex: 1 0%;
  background-color: yellow;
}

#chat {
  flex: 6 0%;
  background-color: orange;
}

#break {
  flex: 1 100%;
}
<div id="left">
  <div id="top">test</div>
  <div id="nav">test</div>
  <div id="main">test</div>
  <div id="break"></div>
  <div id="notepad">test</div>
  <div id="chat">test</div>
</div>
<div id="right">test</div>

https://jsfiddle.net/25qu0b2p/


回答1:


The primary problem is that IE11 is riddled with flexbox-related bugs (flexbugs).

The specific problem is that flex-grow isn't strong enough to get flex items to wrap in IE11.

You have this rule in your code: flex: 1 100%. It uses a shorthand property that breaks down to:

  • flex-grow: 1
  • flex-shrink: 1 (by default)
  • flex-basis: 100%

Because you've set flex-basis to 100%, and the container is set to wrap, that should be enough to get subsequent items to wrap.

Since flex-basis: 100% consumes all space in the row, there's no space remaining for other items. So they must wrap. Chrome gets this.

However, IE11, for whatever reason, sees subsequent items set to flex: 1 0% and says this:

Okay, flex-grow is set to 1, but there's no free space on the line. So there's no space to distribute. And flex-basis is set to 0. This item must be width: 0. No need to wrap anything.

To workaround this logic, while maintaining cross-browser compatibility, add some width to items that must wrap. Try flex-basis: 1px instead of flex-basis: 0.

#nav {
  flex: 1 1px;
  background-color: green;
}

#notepad {
  flex: 1 1px;
  background-color: yellow;
}

revised demo



来源:https://stackoverflow.com/questions/44294703/flex-grow-isnt-rendering-correctly-in-internet-explorer-11-ie11

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