Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical scroll rendering issue in Flexbox in Firefox [duplicate]

I want to contain a flex item within the parent so that it does not spill outside of the parent. Only the flex item should have a scrollbar (if necessary).

My styling works fine within Chrome and IE11, but not Firefox. I suspect there is a difference in interpretation of the flex-basis style set on #wrapper, but I cannot figure out why Firefox renders this differently.

Here's the desired rendering as seen in Chrome:

Chrome rendering screenshot

And here's what happens in Firefox:

Firefox rendering screenshot

I could apply a "duct tape" fix by adding #left { height: calc(100vh - 50px); }, but I'd prefer to identify the actual inconsistency if possible.

body, html, h1 {
  padding: 0;
  margin: 0;
}
header {
  background-color: rgba(0, 255, 255, 0.2);
  height: 50px;
}
#main {
  height: 100vh;
  background-color: rgba(0, 255, 255, 0.1);
  display: flex;
  flex-flow: column;
}
#wrapper {
  display: flex;
  flex-grow: 2;
  flex-basis: 0%;
}
#left {
  overflow-y: scroll;
  background-color: rgba(0, 255, 255, 0.2);
  width: 30%;
}
.box {
  margin: 5px 0;
  height: 50px;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.2);
}
<div id="main">
  <header>
    <h1>Header</h1>
  </header>
  <div id="wrapper">
    <div id="left">
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
    </div>
  </div>
</div>
like image 580
JohnB Avatar asked Oct 02 '15 16:10

JohnB


1 Answers

This has to do with the flexbox specification's implied minimum sizing algorithm.

This is a Firefox bug.

Adding min-width: 0; min-height: 0 to #wrapper seems to do the trick:

#wrapper {
    display: flex;
    flex-grow: 2;
    flex-basis: 0%;
    min-height: 0; /* NEW */
    min-width: 0; /* NEW */
}

DEMO


Original Answer Below

Currently you have overflow-y: scroll applied to #left.

If you also apply overflow-y: scroll to #wrapper, the vertical scroll launches in Firefox.

As to why Firefox interprets the code differently than Chrome I can't say. The rendering engines have their differences. I recently addressed another flexbox interpretation issue between IE11 and Chrome:

More information:

  • Bug 1043520 - (minsizeauto-fallout) Tracking bug for web content breaking due to new "min-width:auto" / "min-height:auto" behavior on flex items

  • Bug 570036 - Flexible box does not allow overflow scrolling of children elements without extra markup

  • DEMO: http://jsfiddle.net/seqgz8qv/ (scroll works in FF)

  • Scroll not working with CSS3 flex box in Firefox

  • Flexbox and vertical scroll in a full-height app using NEWER flexbox api

  • Scrolling a flexbox with overflowing content

like image 58
Michael Benjamin Avatar answered Sep 28 '22 04:09

Michael Benjamin