I'm using flexbox to layout a page because the growing behavior is useful. But I'd like to completely prevent the shrinking behavior.
Anyway to manage this?
Example code:
<div class="flex-vertical-container"> <div class="flex-box"> This one should grow but not shrink </div> <div></div> <div></div> </div>
CSS
.flex-vertical-container { display: flex; flex-direction: column; } .flex-box { flex: 1; }
By default, the child elements of a flexbox container will stretch vertically to fill the height of the container. This can be prevented by using the align-self property on the child element that you do not want to stretch.
A flexbox item can be set to a fixed width by setting 3 CSS properties — flex-basis, flex-grow & flex-shrink. flex-basis : This property specifies the initial length of the flex item. flex-grow : This property specifies how much the flex item will grow relative to the rest of the flex items.
Try setting the flex-shrink
property to 0
on the .flex-box
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With