Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap columns with flexbox are not taking proper width on iOS and Safari

I am trying to use flex box with bootstrap columns so that all the columns are always horizontally centered. The markup mentioned below works fine for firefox, chrome and Android but fails on iOS and safari. I haven't tested IE yet.

HTML:

<!-- The fourth column falls down -->
<div class='row row-1 text-center'>
    <div class="col-xs-3 red">Hi</div>
    <div class="col-xs-3 blue">Hi</div>
    <div class="col-xs-3 blue">Hi</div>
    <div class="col-xs-3 blue">Hi</div>
</div>
<!-- Works Fine and centers the columns -->  
<div class='row text-center'>
    <div class="col-xs-3 red">Hi</div>
    <div class="col-xs-3 blue">Hi</div>
    <div class="col-xs-3 blue">Hi</div>
</div>

CSS:

.row {
    display: flex;
    display: -webkit-flex; 
    flex-wrap:wrap;
    -webkit-flex-wrap: wrap;
    -webkit-justify-content: center;
            justify-content: center;
}
div[class^=col-] {
  float: none;  
  display: inline-block;
  vertical-align: top;
}

On Chrome, Firefox and Android

enter image description here

On Safari and iOS

enter image description here

JSFIDDLE

Is there anything that I should be adding to the columns so that they appear in one line.

like image 856
Kiran Dash Avatar asked Mar 22 '17 10:03

Kiran Dash


People also ask

Does flexbox work in 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.

Can you use flexbox and bootstrap together?

Of course, you can use both in a project. A lot of people is doing that. In fact for making equal height columns you can use flexbox in bootstrap.

How do I change the width and height of my flexbox?

It can be changed by using the flex-direction property. To use flexbox, we have to set display: flex or inline-flex to flex-container. By default, the height and width of a flex-container are set to auto.


1 Answers

It's pseudo-element in the .row causing the problem.

This happens because Safari browser treats :before and :after pseudo-elements as if they were real elements.

Try

 .row:before, .row:after{
      display: none;
    }

or better create a class say, .flex-row and do this

<div class="row flex-row">
  {{contents here..}}
</div>


.flex-row{
     display: flex;
    display: -webkit-flex; 
    flex-wrap:wrap;
    -webkit-flex-wrap: wrap;
    -webkit-justify-content: center;
            justify-content: center;
}
.flex-row:before, .flex-row:after{
   display: none;
}

FIDDLE

like image 105
Jinu Kurian Avatar answered Sep 24 '22 10:09

Jinu Kurian