Row Wrap in flex-box not wrapping in Safari

2020-01-29 04:43发布

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?

4条回答
▲ chillily
2楼-- · 2020-01-29 05:01

I'm using a max-width on my flex items, so I was able to solve this by explicitly setting the max-width within the flex property:

.wrapper {
  display: flex;
  flex-flow: row wrap;
}
li {
  width: 100%;
  max-width: 500px;
  flex: 1 1 500px;
}
查看更多
唯我独甜
3楼-- · 2020-01-29 05:14

Some browsers do not fully support all the CSS3 elements. Try this:

  display:-webkit-box;
  display:-webkit-flex;
  display:-webkit-flexbox;
  display:-moz-flex;
  display:-moz-box;
  display:-ms-flexbox;
  display:flex;
查看更多
老娘就宠你
4楼-- · 2020-01-29 05:18

This is a Safari IOS bug. So the fix / workaround is to set the flex-basis to an explicit width rather than auto for child element.

查看更多
老娘就宠你
5楼-- · 2020-01-29 05:22

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;
} 
查看更多
登录 后发表回答