Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Row Wrap in flex-box not wrapping in Safari

A flex container has four children, each with a flex-basis of 25% an a min-width. flex-flow is set to row wrap. Browsers other then Safari handle this as expected: if the min-width is reached, it wraps the the next item to the next row. In Safari it overflow the container.

See demo here: http://codepen.io/lbilharz/pen/aJbkI

JADE

h1 Why this ain't wrappin' in mobile-safari?   .flex     for i in ['one','two','three','four']       .item         h2=i 

Stylus

.flex   display flex   flex-wrap wrap   flex-direction row   padding 1em   background lightyellow   .item     flex 1 0 25%     padding 1em     box-sizing border-box     min-width 15em 

Any ideas?

like image 556
Lars Bilharz Avatar asked Aug 18 '14 09:08

Lars Bilharz


People also ask

Why is flex-wrap wrap not working?

If you add content and/or width and/or flex-basis to one or more items, and the items grow to exceed 800px (the width of the container), then your flex items will wrap. But note, they won't wrap based on your re-sizing of the browser window, because the container doesn't occupy width: 100% of the viewport.

Does flexbox work in Safari?

Safari versions 9 and up support the current flexbox spec without prefixes. Older Safari versions, however, require -webkit- prefixes. Sometimes min-width and max-width cause alignment problems which can be resolved with flex equivalents.

How do you wrap text in a Flex container?

As you only want the text itself to wrap you need to use flex-wrap: nowrap; to keep . right on the same line. The text will automatically wrap when there is not enough space.

How do you wrap the next line in Flex?

You can use flex-basis: 100% for item you want to wrap in new line.


1 Answers

Per a comment on bugs.webkit.org, it seems the solution is simple!

If your style is

div.flex {     display: -webkit-flex;     display: flex;     -webkit-flex-wrap: wrap;     flex-wrap: wrap;     -webkit-flex-direction: row;     flex-direction: row; } div.flex .item {     min-width: 15em;     -webkit-flex: 1;     flex: 1; } 

you just need to add more explicitness to your flex declaration. In fact, I think only one line needs to change like so

div.flex {     display: -webkit-flex;     display: flex;     -webkit-flex-wrap: wrap;     flex-wrap: wrap;     -webkit-flex-direction: row;     flex-direction: row; } div.flex .item {     min-width: 15em;     -webkit-flex: 1 1 15em; /* this */     flex: 1; }  
like image 97
Joe Hansen Avatar answered Sep 22 '22 13:09

Joe Hansen