Flexbox/IE11: flex-wrap: wrap does not wrap (Images + Codepen inside)

為{幸葍}努か 提交于 2019-12-05 08:35:08

问题


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

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

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

Code Pen Example

View the code here: http://codepen.io/dash/pen/PqOJrG

HTML Code

<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 Code

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;
}

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.

Any ideas how to get IE11 to wrap the images?


回答1:


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;.



来源:https://stackoverflow.com/questions/31022747/flexbox-ie11-flex-wrap-wrap-does-not-wrap-images-codepen-inside

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