Flexbox / IE11:flex-wrap:换行不换行(Images + Codepen里面)

问题描述:

我创建了一个包含社交图标的列表。这些图标应该包装在小屏幕上。

I created a list with social icons. Those icons should wrap on small screens.

我使用 flex-wrap:wrap; 并且它在Firefox中运行良好和Chrome:

I use flex-wrap: wrap; and it works perfect in Firefox and Chrome:

但Internet Explorer 11(和IE 10)不会破坏该行:

But Internet Explorer 11 (and IE 10) will not break the line:

代码笔示例

在此处查看代码: http://codepen.io/dash/ pen / PqOJrG

HTML代码

<div>
  <ul>
    <li><a href="#"><img src="http://placehold.it/40x40" alt=""></a></li>
    <li><a href="#"><img src="http://placehold.it/40x40" alt=""></a></li>
    <li><a href="#"><img src="http://placehold.it/40x40" alt=""></a></li>
    <li><a href="#"><img src="http://placehold.it/40x40" alt=""></a></li>
    <li><a href="#"><img src="http://placehold.it/40x40" alt=""></a></li>
    <li><a href="#"><img src="http://placehold.it/40x40" alt=""></a></li>
    <li><a href="#"><img src="http://placehold.it/40x40" alt=""></a></li>
    <li><a href="#"><img src="http://placehold.it/40x40" alt=""></a></li>
  </ul>
</div>

CSS代码

body {background: #000;}

div {
    background: rgba(255, 255, 255, .06);
    display: table;
    padding: 15px;
    margin: 50px auto 0;
}

ul {
        display: -webkit-flex;
        display: -ms-flexbox;
    display: flex;
        -webkit-flex-wrap: wrap;
        -ms-flex-flow: row wrap;
    flex-wrap: wrap;
        -ms-flex-pack: center;
        -webkit-justify-content: center;
    justify-content: center;
    list-style: none;
    padding: 0;
}

li {
    background: purple;
    margin: 4px;
}

img {
    display: block;
    height: 40px;
    padding: 7px;
    width: 40px;
}

这似乎是一个IE漏洞,当一个flex元素的父容器出现时设置为 display:table; 。删除此行可修复此问题。但是我需要 display:table; 来集中父容器。

This seems to be a IE bug which shows up when a flex element's parent container is set to display: table;. Removing this line fixes the problem. But I need display: table; to center the parent container.

任何想法如何让IE11包装图像?

Any ideas how to get IE11 to wrap the images?

尝试为父容器定义宽度,例如宽度:20%; 。因此,容器将根据您的需要进行格式化,并且flex-wrap将起作用。是的,您可以删除 display:table;

Try defining a width for the parent container, e.g. width: 20%;. Thus, the container will be formatted as you want and flex-wrap will work. And yes, you can remove the display: table;.