Pete Pete - 1 month ago 14
CSS Question

gap below image using flexbox in ie11

So I was trying to answer this question by using only

display:flex
(trying to learn all the little nuances of flex) but I came across a problem that in ie11, there seems to be a space below the image - it looks as if the image-holder is taking the original images height.

Is there an easy fix so that the image holder is as tall as the image inside it?



body,
html {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}

body {
display: flex;
max-height: 100%;
}

.wrapper {
display: flex;
flex-direction: column;
flex-grow: 1;
height: 100%;
max-height: 100%;
width: 100%;
overflow: hidden;
}

header {
background: grey
}

main {
display: flex;
flex-direction: row;
flex: 1;
background: blue
}

.column {
width: 50%;
padding: 10px;
box-sizing: border-box;
display: flex;
flex: 1;
flex-direction: column;
}

.column:first-child {
background: yellow;
}

.column:last-child {
background: green;
}

.image-holder {
margin-bottom: 10px;
background: orange;
}

.image {
width: 100%;
display: block;
height: auto;
}

.scrollable-content {
flex: 1;
background: grey;
position: relative;
height: 10px;
}

.firefox-scroller {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
overflow: auto;
padding: 20px;
box-sizing:border-box;
}

<div class="wrapper">
<header>header</header>
<main>
<div class="column">
<div class="image-holder">
<img src="http://l7.alamy.com/zooms/19704c162b4446c984a50bfdb49b45ac/a-colour-image-taken-on-a-cloudy-dawn-of-the-town-of-saint-malo-from-g1k27a.jpg" alt="" class="image">
</div>
<div class="scrollable-content">
<div class="firefox-scroller">
<h1>I am trying to do:</h1>
<h3>1) make these gray div height 100% till bottom</h3>
<h3>2) When content is more then this gray div should be scrollable or else not</h3>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</p>

</div>
</div>
</div>
<div class="column">
<div class="image-holder">
<img src="http://l7.alamy.com/zooms/19704c162b4446c984a50bfdb49b45ac/a-colour-image-taken-on-a-cloudy-dawn-of-the-town-of-saint-malo-from-g1k27a.jpg" alt="" class="image">
</div>

</div>
</main>
</div>





I've tried playing around with flex-shrink and flex-basis but just couldn't seem to get rid of that space. Stupid ie!

Answer

You can force a reflow in IE with min-height:

example:

body,
html {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}
body {
  display: flex;
  max-height: 100%;
}
.wrapper {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  height: 100%;
  max-height: 100%;
  width: 100%;
  overflow: hidden;
}
header {
  background: grey
}
main {
  display: flex;
  flex-direction: row;
  flex: 1;
  background: blue
}
.column {
  width: 50%;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  flex: 1;
  flex-direction: column;
}
.column:first-child {
  background: yellow;
}
.column:last-child {
  background: green;
}
.image-holder {
  margin-bottom: 10px;
  background: orange;
  min-height: 1%;
  /* added for IE */
}
.image {
  width: 100%;
  display: block;
  height: auto;
}
.scrollable-content {
  flex: 1;
  background: grey;
  position: relative;
  height: 10px;
}
.firefox-scroller {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  overflow: auto;
  padding: 20px;
  box-sizing: border-box;
}
<div class="wrapper">
  <header>header</header>
  <main>
    <div class="column">
      <div class="image-holder">
        <img src="http://l7.alamy.com/zooms/19704c162b4446c984a50bfdb49b45ac/a-colour-image-taken-on-a-cloudy-dawn-of-the-town-of-saint-malo-from-g1k27a.jpg" alt="" class="image">
      </div>
      <div class="scrollable-content">
        <div class="firefox-scroller">
          <h1>I am trying to do:</h1>
          <h3>1) make these gray div height 100% till bottom</h3>
          <h3>2) When content is more then this gray div should be scrollable or else not</h3>
          <p>
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
          </p>

        </div>
      </div>
    </div>
    <div class="column">
      <div class="image-holder">
        <img src="http://l7.alamy.com/zooms/19704c162b4446c984a50bfdb49b45ac/a-colour-image-taken-on-a-cloudy-dawn-of-the-town-of-saint-malo-from-g1k27a.jpg" alt="" class="image">
      </div>

    </div>
  </main>
</div>