Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flex-wrap not working as expected in Safari

Tags:

css

flexbox

On the homepage of http://www.shopifyexperte.de/ there are two flex-box modules, one under "Kundenstimmen" and one under "Neueste Beiträge...". The inner boxes are supposed to wrap when they go below 220px and not grow above 30% width. This works in latest Chrome, FF and Opera (all on Mac), but in Safari 8.0.5 (Mac) and any iOS browser the boxes never form a row even if there's enough room. They always wrap, each one on a row of its own.

The CSS for the container:

.homepage-testimonial-container {  	display: flex;  	display: -webkit-flex;  	-webkit-flex: 1;  	flex: 1;  	-webkit-flex-direction: row;  	flex-direction: row;  	-webkit-flex-wrap: wrap;  	flex-wrap: wrap;  	-webkit-justify-content: space-between;  	justify-content: space-between;  	-webkit-align-items: flex-start;  	align-items: flex-start;  	margin-top: 1em;  }

The CSS for the boxes inside the container:

.homepage-testimonial {  	margin-bottom: 1em;  	min-width: 220px;  	max-width: 30%;  	-webkit-flex: 1 1 auto;  	flex: 1 1 auto;  }

If I disable -webkit-flex-wrap (effectively setting it to nowrap), all boxes line up in a row but eventually overflow the container when the browser window gets too narrow.

Is this some kind of bug in Safari/Webkit or am I doing something wrong here?

like image 978
Tom Borowski Avatar asked May 01 '15 12:05

Tom Borowski


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.

Does flexbox work on all browsers?

Flexbox is very well supported across modern browsers, however there are a few issues that you might run into.

How do you adjust the flex-wrap in CSS?

The CSS flex-wrap property is used to specify whether flex items are forced into a single line or wrapped onto multiple lines. The flex-wrap property allows enabling the control direction in which lines are stacked. It is used to designate a single line or multi-line format to flex items inside the flex container.


2 Answers

It seems this is a bug in Safari. In a separate issue, I tested using the min-width in place of auto in lines where you say something like -webkit-flex: 1 1 auto;.

This question has some info: https://stackoverflow.com/a/30792851/756329

like image 180
Joe Hansen Avatar answered Oct 09 '22 07:10

Joe Hansen


Set child elements like this seems to work for me

flex: 1 0 auto; 
like image 41
socrateisabot Avatar answered Oct 09 '22 09:10

socrateisabot