title: Why is content overflowing in flexbox?
body: <p>I am experiencing some behavior that I don't understand. When I set up a list of badges with a max-height on the list and margin on the list items then the content for the list items overflows their containers proportionally to the margin.</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>.badgers {
    display: flex;
    flex-direction: column;
    max-height: 10em;
    overflow: auto;
    border: 1px dashed red;
  }
  
  .badge, .title, .location, .timestamp {
    display: flex;
  }
  
  .badge {
    flex-direction: column;
    border: 1px solid black;
    margin: 1em 0;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="badgers"&gt;
    &lt;div class="badge"&gt;
        &lt;span class="title"&gt;Title&lt;/span&gt;
        &lt;span class="location"&gt;Location&lt;/span&gt;
        &lt;span class="timestamp"&gt;Timestamp&lt;/span&gt;
    &lt;/div&gt;
    &lt;div class="badge"&gt;
        &lt;span class="title"&gt;Title 2&lt;/span&gt;
        &lt;span class="location"&gt;Location&lt;/span&gt;
        &lt;span class="timestamp"&gt;Timestamp&lt;/span&gt;
    &lt;/div&gt;
    &lt;div class="badge"&gt;
        &lt;span class="title"&gt;Title 3&lt;/span&gt;
        &lt;span class="location"&gt;Location&lt;/span&gt;
        &lt;span class="timestamp"&gt;Timestamp&lt;/span&gt;
    &lt;/div&gt;
  &lt;/div&gt;
    </code></pre>
  </div>
  </div>
  </p>
  
  <p>If I remove the margin then there is no overflow.</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>.badgers {
    display: flex;
    flex-direction: column;
    max-height: 10em;
    overflow: auto;
    border: 1px dashed red;
  }
  
  .badge, .title, .location, .timestamp {
    display: flex;
  }
  
  .badge {
    flex-direction: column;
    border: 1px solid black;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="badgers"&gt;
    &lt;div class="badge"&gt;
        &lt;span class="title"&gt;Title&lt;/span&gt;
        &lt;span class="location"&gt;Location&lt;/span&gt;
        &lt;span class="timestamp"&gt;Timestamp&lt;/span&gt;
    &lt;/div&gt;
    &lt;div class="badge"&gt;
        &lt;span class="title"&gt;Title 2&lt;/span&gt;
        &lt;span class="location"&gt;Location&lt;/span&gt;
        &lt;span class="timestamp"&gt;Timestamp&lt;/span&gt;
    &lt;/div&gt;
    &lt;div class="badge"&gt;
        &lt;span class="title"&gt;Title 3&lt;/span&gt;
        &lt;span class="location"&gt;Location&lt;/span&gt;
        &lt;span class="timestamp"&gt;Timestamp&lt;/span&gt;
    &lt;/div&gt;
  &lt;/div&gt;
    </code></pre>
  </div>
  </div>
  </p>
  
  <p>If I change the wrapper to <code>display: block</code> and leave the margin then the list looks like what I want.</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>.badgers {
    max-height: 10em;
    overflow: auto;
    border: 1px dashed red;
  }
  
  .badge, .title, .location, .timestamp {
    display: flex;
  }
  
  .badge {
    flex-direction: column;
    border: 1px solid black;
    margin: 1em 0;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="badgers"&gt;
    &lt;div class="badge"&gt;
        &lt;span class="title"&gt;Title&lt;/span&gt;
        &lt;span class="location"&gt;Location&lt;/span&gt;
        &lt;span class="timestamp"&gt;Timestamp&lt;/span&gt;
    &lt;/div&gt;
    &lt;div class="badge"&gt;
        &lt;span class="title"&gt;Title 2&lt;/span&gt;
        &lt;span class="location"&gt;Location&lt;/span&gt;
        &lt;span class="timestamp"&gt;Timestamp&lt;/span&gt;
    &lt;/div&gt;
    &lt;div class="badge"&gt;
        &lt;span class="title"&gt;Title 3&lt;/span&gt;
        &lt;span class="location"&gt;Location&lt;/span&gt;
        &lt;span class="timestamp"&gt;Timestamp&lt;/span&gt;
    &lt;/div&gt;
  &lt;/div&gt;
    </code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>So why does the content overflow when the list is <code>display: flex; flex-direction: column</code> but not when it is <code>display: block</code>?</strong></p>