Languages
[Edit]
EN

CSS - scrolling for flexbox with overflowing content

4 points
Created by:
Isaiah89
721

In this article we would like to show how to enable scrolling for overflowing content with flexbox in CSS.

Scrolling for overflowing content with flexbox in CSS
Scrolling for overflowing content with flexbox in CSS

We have two simple solutions:

  1. position: absolute for scrolled element,
  2. min-height: 0 for parent elements of scrolled element.

1. position: absolute for scrolled element example

Edit

In this solution we set size by stretching to avaialbe space with absolute position.

 

2. min-height: 0 for parent elements example

Edit

Parent elements should have min-height set to 0. Additionaly we need to use flex: 1 and overflow-y: auto for element we want to have scrolling.

2.1 One nesting level example

Edit

It is important to provide proper height for container. It can done by stretching container in parent element or with fixed height.

Parent element for scrolled element should have set min-height: 0 always.

2.2. Many nested components example

Edit

It is important to provide proper height for main container. It can done by stretching container in parent element or with fixed height.

Two parent elements for scrolled element should have set min-height: 0 always.

 

Alternative titles

  1. CSS - scrollable container with dynamic height using flexbox
  2. CSS - flexbox with scrollable child
  3. CSS - create horizontally scrollable content with flexbox
  4. CSS - flex with scroll property
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

CSS

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join