Flexbox children rendering wrong in Safari

时间:2015-06-25 18:55:39

标签: html css safari flexbox

I have the following HTML and css that works great in Firefox and Chrome to create a 3-column grid of boxes. But, in Safari it takes all the boxes and puts them into 1 row, squishing the width of each one so it will fit instead of allowing the float to push the boxes to a new line. How can I get it to looks the same in Safari, any ideas? (note: the html class '.box' is in a loop that dynamically generates boxes based on user input, so the number of boxes is variable) HTML: <div id="home-grid"> <div class="box"> Contents of box </div> </div> CSS: #home-grid { margin-top: 20px; float: left; display: -webkit-box; /* OLD: Safari, iOS, Android browser, older WebKit browsers. */ display: -moz-box; /* OLD: Firefox (buggy) */ display: -ms-flexbox; /* MID: IE 10 */ display: -webkit-flex; /* NEW, Chrome 21–28, Safari 6.1+ */ display: flex; /* NEW: IE11, Chrome 29+, Opera 12.1+, Firefox 22+ */ flex-flow: row wrap; justify-content: space-between; width: 100% } #home-grid .box { position: relative; float: left; width: 192px!important; height: 180px; border: 1px solid #F73987; margin-bottom: 20px; overflow: hidden; }

1 个答案:

答案 0 :(得分:1)

通过添加以下两行,我能够在最新版本的Safari中使用它:

-webkit-flex-flow: row wrap;
-webkit-justify-content: space-between;

see jsfiddle

为了澄清,根据caniuse.com

,Safari仍然需要-webkit前缀