Flexbox container with absolute position does not match content width in IE

I'm new to flexbox, my problem is this:

I have a submenu in my navigation, placed absolutely and using flexbox.

Everything works fine in Chrome / Firefox, has not tested Safari.

IE11 shows my submenu, but its children overflow (which breaks mine :hover).

Check this code in IE to see the problem (simplified version):

https://codepen.io/CamilleVerrier/pen/GvLojN

I tried many things suggested in StackOverflow or CanIUse, for example, as an individual definition of flexibility:

ul.sub-menu li {
    flex-grow:0;
    flex-shrink:1;
    flex-basis:0px;
}

But that does not work.

During my tests, I found that if I delete position:absolute, everything will work again (but my menu is clearly breaking through).

... ? (, ahah)

! ( )

/* General styles */

body {
  background: tomato;
  font-size: 1.2rem;
  font-weight: bold
}

a {
  color: black;
  text-decoration: none;
}

li {
  list-style: none;
}

ul li {
  font-size: 1.6rem;
  display: inline-block;
  margin-left: 40px;
  text-transform: uppercase;
}

ul li.menu-metier {
  position: relative;
  padding-bottom: 25px;
}


/* SubMenu */

ul.sub-menu {
  display: -webkit-box;
  display: flex;
  display: -ms-flexbox;
  position: absolute;
  background: white;
  top: 45px;
  left: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}

ul.sub-menu li {
  margin: 10px;
  flex-grow: 0;
  flex-shrink: 1;
  flex-basis: auto;
}

ul.sub-menu li a {
  display: -ms-flexbox;
  display: flex;
  flex-direction: column;
}

ul.sub-menu li a img {
  padding: 0;
  margin-bottom: 5px;
  align-self: center;
}

ul.sub-menu li a span {
  text-align: center;
  font-size: 1rem;
  align-self: center;
}
<ul>
  <li><a href="#"><span>Accueil</span></a></li>
  <li class="menu-metier"><a href="#"><span>Notre métier</span></a>
    <ul class="sub-menu">
      <li>
        <a href="#">
          <img width="170" height="102" src="http://lorempixel.com/170/102">
          <span>Séminaire et Incentive</span>
        </a>
      </li>
      <li>
        <a href="#">
          <img width="170" height="102" src="http://lorempixel.com/170/102">
          <span>Congrès et rencontres</span>
        </a>
      </li>
      <li>
        <a href="#">
          <img width="170" height="102" src="http://lorempixel.com/170/102">
          <span>Communication Design</span>
        </a>
      </li>
    </ul>
  </li>
  <li>
    <a href="#">
      <span>L’agence</span>
    </a>
  </li>
  <li>
    <a href="#">
      <span>Photos</span>
    </a>
  </li>
</ul>
Hide result
+4
2

flexbox.

.

position: relative , position: absolute.

Chrome .

IE11 . .

position: relative . ( , , (.. )).

ul li.menu-metier {
   /* position: relative; */
   padding-bottom: 25px;
}

right .

ul.sub-menu {
    right: -600px;
}

.

. , IE.

.

+2

flex-basis, , IE, width, .

https://codepen.io/anon/pen/wqZWav

0

Source: https://habr.com/ru/post/1685069/


All Articles