Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flexbox not working on iPad and Safari [duplicate]

Tags:

html

css

flexbox

I'm using flexbox on a website and it crashes on iPad Air, iPad 3 and Safari PC.

The design and the code is similar to this codepen. http://codepen.io/anon/pen/xwJzEg/

display: flex;
flex-wrap: wrap;

This is how it looks on those devices where the problem occurs:enter image description here

Any advice how to workaround this?

like image 384
Chriss Avatar asked Nov 03 '15 15:11

Chriss


People also ask

Does flexbox work on Safari?

Safari 14.1 now supports the gap property inside Flexbox containers, along with row-gap and column-gap . Gaps in Flexbox make it possible for web developers to create space between Flex items without resorting to annoying margin hacks.

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.

Is flexbox new?

Flexbox was introduced in 2009 as a new layout system, with the goal to help us build responsive web pages and organize our elements easily, and since then, it's gained more and more attention. It turns out it's now used as the main layout system for modern web pages.


3 Answers

You may want to consider Safari browser support for flexbox.

Although Safari 9 supports all standard flex properties, with Safari 8 and older you'll need to use vendor prefixes.

Make this adjustment to your code:

.container {
    list-style: none;
    margin: 0;
    padding: 0;
    display: -webkit-flex; /* NEW */
    display: flex;
    -webkit-flex-wrap: wrap; /* NEW */
    flex-wrap: wrap;
    font-family: "Open Sans";
}

See flexbox browser support here: http://caniuse.com/#search=flexbox

Consider using Autoprefixer.

See flexbox code samples with prefixes: The Ultimate Flexbox Cheat Sheet

like image 58
Michael Benjamin Avatar answered Oct 12 '22 04:10

Michael Benjamin


I used Autoprefixer as suggested in the answers.

I use gulp to handle this when I write SASS. Here is a guide.

Answers here are suggesting to use a prefixed property before the non prefixed one. I agree with a small correction.

.container {
    display: -webkit-flex;
    -webkit-flex-wrap: wrap;
    display: flex;   
    flex-wrap: wrap;
}

Ideally, you need to list all of the prefixed properties before you start using the non prefixed ones. @Michael_B answer is not perfect in my opinion.

I hope people will find this useful.

like image 33
Andrejs Gubars Avatar answered Oct 12 '22 04:10

Andrejs Gubars


Have you tried setting flex values for the first-child and last-child li elements? I've found that iPads can get confused if none of the flex-items in a flex-container have a flex value. For example:

.container li:first-child {
    flex:1; 
    -webkit-box-flex:1; 
    -webkit-flex:1;
}
.container li:nth-child(4) {
    flex:1; 
    -webkit-box-flex:1; 
    -webkit-flex:1;
}
like image 37
user3487028 Avatar answered Oct 12 '22 05:10

user3487028