Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

Chrome, Firefox

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

IE 11

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?

like image 503
dash Avatar asked Jun 24 '15 09:06

dash


1 Answers

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

like image 53
jhorapb Avatar answered Oct 08 '22 17:10

jhorapb