Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flex-box: shrink before wrap

Tags:

css

flexbox

I have a layout with multiple columns, of which some are fixed and others stretch as needed. Therefore, I use flexbox. Additionally, I want and need to use flex-wrap.

The structure is like this:

<div class="row" style="display: flex; flex-flow: row wrap">     <div class="column fixed" style="flex: 0 0 auto"></div>     <div class="column stretch" style="flex: 1 1 auto"></div>     <div class="column fixed" style="flex: 0 0 auto"></div> </div> 

Please see http://jsfiddle.net/mh3rypqj/1/

Now everything works as expected as long as we are talking about empty divs. Once I put a p in the stretch column, wrapping and shrinking behaves differently.

My expected behaviour when space is getting smaller: First shrink, then wrap. Shrink the .stretch. Once min-width is reached, wrap the elements.

The behaviour I get once I put the p in .stretch: First wrap, then shrink. The row is first wrapped. Shrinking only occurs after everything is wrapped.

I want to have First shrink, then wrap. In short, I want the second row in the JSFiddle to behave just like the first. What do I have to do?

like image 911
Joshua Gleitze Avatar asked Sep 30 '14 16:09

Joshua Gleitze


Video Answer


1 Answers

Set flex-basis equal to min-width:

.column.stretch {     flex: 1 1 100px; /* or 1 0 100px, and no more need in min-width at all */     max-width: 300px;     min-width: 100px;     background: red; } 

edited JSfiddle example

like image 152
Ilya Streltsyn Avatar answered Sep 20 '22 02:09

Ilya Streltsyn