0

In Chrome, Safari and surprisingly IE 11 if a container has display: flex; flex-direction: column; height: 100% you can set the child to flex: 1 and have it take as much height as it can without going beyond the bounds of it's container's height.

That allows me to put scrollbars not on the page but on the .scrollable container very easily.

Here's the example:

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

or

body, html {
  overflow: hidden;
  height: 120px;
}

.container {
  width: 500px;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  height: 100%;
}

.header {
  background: cyan;
  flex: 0 0 50px;
  margin: 5px 0
}

.content {
  flex: 1;
  display: flex;
}

.scrollable {
  width: 100%;
  overflow: auto;
}

.item {
  background: red;
  height: 10px;
  width: 100%;
  margin-bottom: 5px;
}
<div class="container">
  <div class="header">Header</div>
  <div class="content">
    <div class="scrollable">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>
  </div>
</div>

However, running this in Chrome and Edge I'm forced to do the following on my .content container: * remove the flex: 1; line * add height: calc(100% - 60px) where 60px is my header's height + margin

Why is FF and Edge behaving differently, and how can I avoid using height calculations?

Thanks,

LanFeusT
  • 2,392
  • 5
  • 38
  • 53

0 Answers0