I have a flex container in which I want to have another flex container which scrolls content when it is too large to fit the screen. This is what I have so far:
<Box
sx={{
m: 'var(--Content-margin)',
p: 'var(--Content-padding)',
width: 'var(--Content-width)',
flex: 1,
display: 'flex',
flexDirection: 'column',
backgroundColor: 'green',
}}
>
<Box sx={{ flex: 1, overflow: 'scroll', backgroundColor: 'orange' }}>
... // long list of content
</Box>
</Box>
I have tried playing around with all parameters but it does not work. It always adds the browser default scrolling and content just grows downwards.
Currently looks like the following. As you can see, the scrolling is on the browser level and not on the orange box:
2
Answers
You need to add a height to the orange box which fits the screen size. That way, the orange box won’t be bigger than the screen and the overflow will work.
The easiest way I know to fix this issue is to use flexbox with a height of 100% in the main container, this way it will adapt the height of the container to 100% of the screen size excluding the height of the nav.
I added an example here https://codepen.io/mariajunqueira/pen/gONRveV