title: css - scroll issue with flexbox and max-height
body: <p>I'm facing a strange issue that might have link with <a href="https://stackoverflow.com/questions/22914399/flexbox-misbehaving-with-max-height">flexbox misbehaving with max-height</a>, but so far I didn't find any pure css solution.</p>
  
  <hr>
  
  <p>I made a plunker to summarize the problem. If you resize your window to reduce its height, at some point you should have a scrollbar in the first block, but if you get back to a higher height, even if there is enough space, the scrollbar won't disappear unless you put your mouse over it (which feels very bugy) : <a href="https://plnkr.co/edit/VsJ7Aw8qZdSM1iJeL7Bj?p=preview" rel="nofollow">https://plnkr.co/edit/VsJ7Aw8qZdSM1iJeL7Bj?p=preview</a></p>
  
  <p>I have a main container (in flex) containing 2 blocks (also in flex).<br/>
  The main container has its height set to 100%, allowing it to resize itself following the window size.<br/>
  Both children have a fixed content and an overflow-y set to auto.<br/>
  The first child has a max-height in % to let more height to the second child.</p>
  
  <p>The issue seems to come from this max-height rule. If you remove it, then there's no problem, but I need this max-height...<br/>
  I don't want to use something like:</p>
  
  <pre><code>.max { flex: 1 1 auto; }
  .all { flex: 3 1 auto; }
  </code></pre>
  
  <p>because it would make my first block higher than its content depending on the window size. I want the first block to have at most its content height.</p>
  
  <p>So my question is: Is it an implementation issue in many browsers (maybe all, but I only tested it in Chrome, IE10 and IE11), or is something wrong in my logic ?
  Thank you.</p>
  
  <hr>
  
  <p>UPDATE: I used a fixed height for my content in this example, but in my project it's a list of n elements in it. So I can't really set my max-height with px value.</p>
  
  <hr>
  
  <p>UPDATE2: I can't use vh in .max max-height property because it takes 100vh as 100% of viewport height (basically your browser window height). But in my context, .main is already in other containers. Those containers have already their heights defined and are smaller than my window height.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>/* Styles go here */
  
  html {
    height: 100%;
  }
  body {
    height: calc(100% - 16px);
  }
  .main {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
  }
  .max,
  .all {
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow-y: auto;
  }
  .max {
    flex: 0 1 auto;
    min-height: 103px;
    max-height: 40%;
    background-color: green;
  }
  .all {
    flex: 2 1 auto;
    min-height: 235px;
    background-color: blue;
  }
  .content {
    flex: 0 0 auto;
    box-sizing: border-box;
    height: 200px;
    margin: 5px;
    border: 1px dashed black;
    background-color: white;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;link rel="stylesheet" href="style.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div class="main"&gt;
      &lt;div class="max"&gt;
        &lt;div class="content"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="all"&gt;
        &lt;div class="content"&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>