3

I am using display flex for an element (.outer) which should adjust its height to the content but must not exceed a certain height (e.g. 100px).

Once the height is exceeded I want that the content inside to start to scroll vertically.

This behaviour works as expected on Chrome but in Firefox the content wrapper (.wrapper) growth to the height of its content (.list) and therefore it is not scrollable.

You can try it yourself using this simplified example:

.outer {
  display: flex;
  max-height: 100px;
  overflow: hidden;
  flex-direction: column;
}

.wrapper {
  display: flex;
  width: 100%;
  height: 100%;
}

.list {
  width: 100%;
  background: purple;
  overflow: scroll;
}
<div class="outer">
  <div class="wrapper">

    <div class="list">
      <p>1</p>
      <p>2</p>
      <p>3</p>
      <p>4</p>
      <p>5</p>
    </div>

  </div>

</div>

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


Setting max-height to height solves the scroll problem but causes a white space if the content is not high enough.

Talie
  • 51
  • 6

2 Answers2

5

add min-height:0 to the .wrapper class. It will work.

Priyanjit
  • 305
  • 3
  • 9
1

This should fix

.wrapper {
  display: flex;
  width: 100%;
  height: 100%;
  min-height:0;
}
Supratik Rulz
  • 235
  • 2
  • 8