How to add overflowY to a flexbox child only without height: calc function?

yotube
0

Issue

I have a quite complex layout. If simplified it's a flexbox with two child flexbox items. Parent flexbox takes full height of a screen and child flexboxes takes full height as well.

How can I make a one child flexbox take full screen height and if its bigger than a user screen then scrollY should appear for that child? I'm trying to find a solution without calc function ...how can I make it another way (might be it is possible with height: 100%)?

The amount of content in child can be different so I need overflowY only if content exceeds screen size. In the code example below I need blue container take full height and scrollY because there's lot of content.

Here's codesandbox: https://codesandbox.io/s/modest-leakey-bk75j8?file=/src/App.js

export default function App() {
return (
<div
style={{
display: "flex",
gap: "20px",
background: "pink",
minHeight: "100vh"
}}
>
<div
style={{
flex: 1,
background: "green"
}}
>
Container 1
</div>
<div
style={{
flex: 1,
background: "lightblue",
height: "500px",
overflow: "auto"
}}
>
<p>{TEXT}</p>
<p>{TEXT}</p>
<p>{TEXT}</p>
</div>
</div>
);
}

Solution

I believe you just need to change one line in light blue box's style to achieve what you have described. Just change the maxHeight to maxHeight: "100vh".

Then it becomes:

<div
style={{
flex: 1,
background: "lightblue",
maxHeight: "100vh",
overflow: "auto"
}}
>


Answered By - ilketorun
Tags

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top