Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex items overflowing container in IE11

My flex container has a horizontal list of items which all browsers display properly inside their parent except IE11, that seems incapable of keeping them within it, instead they "bleed out" of it, like so:

enter image description here

Below is a simplified Fiddle of my setup which demonstrates the problem in action:

ul, li {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul {
  display: flex;
  width: 200px;
  border: 1px dashed red;
}

li img {
  max-width: 100%;
  height: auto;
}
<ul>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
</ul>

Result on Chrome: enter image description here

Result on IE11: enter image description here

Any workaround?

like image 515
drake035 Avatar asked Apr 11 '17 18:04

drake035


People also ask

Does Flexbox work in ie11?

Note also that Internet Explorer 11 supports the modern display: flex specification however it has a number of bugs in the implementation.

How do you specify how Flex items are laid out in the container?

The flex-direction property specifies how flex items are placed in the flex container, by setting the direction of the flex container's main axis. This determines the direction in which flex items are laid out.


1 Answers

It looks like IE11 requires you to define a size for the flex items (li):

ul, li {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul {
  display: flex;
  width: 200px;
  border: 1px dashed red;
}
 
li {              /* NEW */
  flex: 0 1 100%; /* flex-grow, flex-shrink, flex-basis */
  /* flex: 1 */   /* alternatively, this also works (short for: fg:1, fs:1, fb:0px) */
}

li img {
  max-width: 100%;
  height: auto;
}
<ul>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
  <li><img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""></li>
</ul>

revised fiddle

like image 89
Michael Benjamin Avatar answered Sep 19 '22 08:09

Michael Benjamin