2

I was having issues with a div that has a dynamic height that is scrollable inside a flex-box. The sample below shows what is happening.

  • Why don't the pixel units of height translate 1:1 inside a flexed box?
  • Why DO the pixel units of min-height translate 1:1 inside a flexed box?

You can see for yourself by adding more content to both .content.mid elements, the box with min-height retains it's height of 30px yet the box with height gets smaller and smaller as the flex-grow container gets bigger and bigger.

This was tested on Chrome/53.0.2785.143

.content{
  display: flex;
  position: absolute;
  flex-direction:column;
  border: 1px solid black;
  left:10px;
  top: 10px;
  height:200px;
  width:300px;
}

.content div{
  border: 1px solid green;
}
.mid{
  flex-grow:1;
  overflow:auto;
}
.top,.bot{
  box-sizing: border-box;
  min-height:30px;
}
.content.bad{
  left:320px;
}
.top.bad,.bot.bad{
  min-height:auto; /* reset min-height */
  height: 30px;
}
<div class="content">
  <div class="top">actual height = 30px (with min-height)</div>
  <div class="mid">scrollable<br>a<br>b<br>c<br>d<br>e<br>f<br>f<br>f<br>f<br>f<br>f<br></div>
  <div class="bot">actual height = 30px (with min-height)</div>
</div>

<div class="bad content">
  <div class="bad top">actual height != 30px (with height)</div>
  <div class="bad mid">scrollable<br>a<br>b<br>c<br>d<br>e<br>f<br>f<br>f<br>f<br>f<br>f<br></div>
  <div class="bad bot">actual height != 30px (with height)</div>
</div>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Isaac
  • 11,409
  • 5
  • 33
  • 45
  • An initial setting of a flex container is `flex-shrink: 1`. This means that, by default, flex items will be allowed to shrink past their initial size. Disable this feature with `flex-shrink: 0` on items that should retain their defined `width` / `height` ([demo](https://jsfiddle.net/jugcqmny/)). For a more complete explanation, see ***The `flex-shrink` factor*** section in the dupe. – Michael Benjamin Oct 10 '16 at 00:33

0 Answers0