Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flexbox: distribute elements vertically in Safari

Tags:

css

flexbox

I need to distribute three items in the mobile portrait view. Used flex and it works in all others browsers except safari. so it is not working in iphone.

I have used align-content: space-between; and flex-flow: row wrap; together to get the alignment. What are the correct properties to be used to make it work in Safari?

-> Here is the fiddle

*{
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
html, body{
  height: 100%;
  margin: 0;
}
.wrap{
  display: -webkit-box;display: -ms-flexbox;display: flex;
  -webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column;
  -ms-flex-line-pack: justify;align-content: space-between;
  width: 100%;
  border: 1px solid red;
  height: 100%;
  
  -webkit-flex-flow: row wrap;
   flex-flow: row wrap;

}
div[class*="col"]{
  height: 50px;
  width: 100%;
  border: 1px solid green;
}
<div class="wrap">
  <div class="col1">

  </div>
  <div class="col1">

  </div>
  <div class="col1">

  </div>
</div>
like image 279
Felix A J Avatar asked Jul 14 '16 11:07

Felix A J


People also ask

How do I arrange vertically in flexbox?

The text content can be aligned vertically by setting the following display properties: align-items. justify-content. flex-direction.

Is Flex supported on 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. See Flex items not stacking properly in Safari.

Does Z Index work with flexbox?

Flexbox and z-index. As you probably already know, the z-index property works only on positioned elements. By default, all elements have position: static and aren't positioned. An element is “positioned” when its position property is set to relative , absolute , fixed , or sticky .


1 Answers

Your code is missing the necessary -webkit- prefixes for older Safari versions:

display: -webkit-flex;
display: flex;

-webkit-flex-direction: column;
flex-direction: column;

-webkit-align-content: space-between;
align-content: space-between;

-webkit-flex-flow: row wrap;
flex-flow: row wrap;

References:

  • http://www.sketchingwithcss.com/samplechapter/cheatsheet.html
  • http://caniuse.com/#search=flexbox (click "Show all")
  • https://stackoverflow.com/a/35137869/3597276
like image 59
Michael Benjamin Avatar answered Oct 21 '22 10:10

Michael Benjamin