Home > Software engineering >  Firefox scrollbar shrinks flex children when using align-items: flex-start
Firefox scrollbar shrinks flex children when using align-items: flex-start

Time:08-24

The following example renders correctly in Chrome, but in Firefox the 'inner' container does not expand to accomodate the scrollbar and creates a horizontal scroll bar instead. Is it a bug or how to work around this issue?

.line {
  width: 300px;
  border: 1px solid red;
}
.parent {
  display: flex;
  flex-direction: column;
  height: 150px;
  align-items: flex-start;
}
.inner {
  flex-basis: 0;
  flex-grow: 1;
  overflow-y: auto;
}
<div >
  <div >Line</div>
  <div >
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
  </div>
</div>

CodePudding user response:

Adding the line

scrollbar-gutter: stable

should solve the problem

.line {
  width: 300px;
  border: 1px solid red;
}
.parent {
  display: flex;
  flex-direction: column;
  height: 150px;
  align-items: flex-start;
}
.inner {
  flex-basis: 0;
  flex-grow: 1;
  overflow-y: auto;
  scrollbar-gutter: stable
}
<div >
  <div >Line</div>
  <div >
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
    <div >Line</div>
  </div>
</div>

  • Related