Nested flexbox error in IE

I have nested flexboxes with some images inside, it looks good in Chrome, but in IE you can see that the borders flex-item-wrapperdon't match the bottom of the image. By the way, in the layout I sometimes will have several flex-rowwith many pictures.

.flex-list {
  display: flex;
  flex-direction: column;
}
.flex-row {
  display: flex;
}
.flex-item-wrapper {
  width: 100%;
  border: 1px solid green;
}
.flex-item {
  height: 100%;
  width: 100%;
  border: 1px solid blue;
}
.picture {
  width: 100%;
}
<div class="flex-list">
  <div class="flex-row">
    <div class="flex-item-wrapper">
      <div class="flex-item">
        <a href='#'>
          <img class="picture" src="http://www.picgifs.com/clip-art/cartoons/super-mario/clip-art-super-mario-832109.jpg" alt="">
        </a>
      </div>
    </div>
    <div class="flex-item-wrapper"></div>
    <div class="flex-item-wrapper"></div>
    <div class="flex-item-wrapper"></div>
  </div>
</div>
Run codeHide result
+4
source share
2 answers

This seems to work:

.flex-row {
  display: flex;
  flex: 0 0 auto; /*added*/
}

or

.flex-row {
  display: flex;
  height: 100%; /*added*/
}

See a simplified demo:

.flex-list {
  display: flex;
  flex-direction: column;
}
.flex-row {
  display: flex;
  flex: 0 0 auto;
}
.flex-item {
  flex: 1;
  border: 1px solid blue;
}
.picture {
  width: 100%;
  height: auto;
}
<div class="flex-list">
  <div class="flex-row">
    <div class="flex-item">
      <a href='#'>
        <img class="picture" src="http://www.picgifs.com/clip-art/cartoons/super-mario/clip-art-super-mario-832109.jpg" alt="">
      </a>
    </div>
    <div class="flex-item"></div>
    <div class="flex-item"></div>
    <div class="flex-item"></div>
  </div>
</div>
Run codeHide result
+2
source

The problem arises due to the nesting of flexbox. This fix is:

.flex-row {
  width: 100%;
  align-self: flex-start;
}

.flex-list {
  display: flex;
  flex-direction: column;
}
.flex-row {
  display: flex;
  width: 100%;
  align-self: flex-start;
}
.flex-item-wrapper {
  width: 100%;
  border: 1px solid green;
}
.flex-item {
  height: 100%;
  width: 100%;
  border: 1px solid blue;
}
.picture {
  width: 100%;
}
<div>
  <div class="flex-list">
    <div class="flex-row">
      <div class="flex-item-wrapper">
        <div class="flex-item">
          <a href='#'>
            <img class="picture" src="http://www.picgifs.com/clip-art/cartoons/super-mario/clip-art-super-mario-832109.jpg" alt="">
          </a>
        </div>
      </div>
      <div class="flex-item-wrapper"></div>
      <div class="flex-item-wrapper"></div>
      <div class="flex-item-wrapper"></div>
    </div>
  </div>
  <div></div>
</div>
Run codeHide result
+1
source

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


All Articles