Right now I have a flex column with two items in it, and I'm trying to figure out how to get the behavior I'm looking for. In particular, I'm trying to enforce that items within have certain minimum and maximum heights.
- The first item
item1
is on top. It should grow to encompass as much vertical space as it needs, but should not shrink below 50% under any circumstance; if the contents are larger than this, it should scroll vertically. - The second item
item2
is in the middle. It is no larger than its contents, but should not grow beyond 50% under any circumstance; if the contents are larger than this, it should scroll vertically. - In the scenario where
item1
would stretch beyond 50%, butitem2
does not,item2
should not shrink so that it is smaller than its contents.item1
should develop a vertical scrollbar instead. - In the scenario where both
item1
anditem2
are bursting at the seams with content (too much to fit in the available space), they should both take up 50% of the available space. This is to say, the growth ofitem2
takes precedence over the growth ofitem1
. - The entire column should always stay within a fixed height.
(I promise I'm not trying to be demanding, I'm just trying to be really super specific!)
Here's the SCSS code I currently have:
.column {
display: flex;
flex-direction: column;
.item1 {
flex: 1 1 auto;
overflow-y: scroll;
}
.item2 {
flex: 0 1 auto;
overflow-y: scroll;
}
}
This gets me most of the way there, but in the case where both items grow out of control, item2
ends up growing to overtake item1
. Also, in the case where only item1
becomes overlarge, item2
shrinks down, which I'd rather not have.
But to summarize, and really answer the most pressing part of this question, can I use maximum heights and minimum heights in combination with Flexbox, and how? Simply adding min-height
and max-height
appears to have no effect.
EDIT: someone asked for a working example. This should work, though it might make you go blind.
https://jsfiddle.net/TheSoundDefense/oxykdhpt/1/
EDIT 2: the code now has item1
and item2
in isolation, making item3
irrelevant, so I removed it.