Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent flexbox shrinking

Tags:

css

flexbox

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; } 
like image 715
Simon Boudrias Avatar asked Mar 19 '15 23:03

Simon Boudrias


People also ask

How do I stop my flexbox from stretching?

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.

How do I fix my flexbox size?

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.


1 Answers

Try setting the flex-shrink property to 0 on the .flex-box.

like image 170
zgood Avatar answered Sep 22 '22 02:09

zgood