Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you make a flexbox child expand to fit parent but not contents?

Tags:

css

flexbox

I'm using a flexbox to make a div take up the remaining vertical space in the browser window, but I'd like to prevent it from expanding beyond that. When its contents exceed its vertical size, I'd like a scrollbar to show up in the flexbox child that is now too small.

Is this possible? Or is there some other layout technique I should be using for this?

Here's a link to a JSFiddle to show the situation: https://jsfiddle.net/83990d3a/

The other vertical space is taken up with a toolbar, the exact vertical size of which is not known beforehand.

like image 375
Curyous Avatar asked Sep 17 '15 21:09

Curyous


People also ask

Which flex property will use to prevent child element to flow out of parent width?

To override this behavior, use min-width: 0 or overflow: hidden .

Should display flex applies to the parent or child element?

The flexbox code is triggered on the parent element, but affects all of the child elements.

What are disadvantages of flexbox?

One of the major drawbacks of using flexbox is performance issues. The use of flexbox can increase the page loading time if you have a larger project. You can compare the page loading time through Chrome development tools using the flexbox and the same pages constructed without using flexbox.


1 Answers

Just add overflow: auto to #content (updated fiddle):

#content {
    background-color: #ceecf5;
    flex-grow: 1;
    overflow: auto;
}
like image 139
Ori Drori Avatar answered Sep 22 '22 02:09

Ori Drori