Flexbox wraps last column of the first row in Safari

前端 未结 12 662
长发绾君心
长发绾君心 2020-11-30 18:52

The last column of the first row is wrapped to the next line when viewing in Safari, and some other iOS based browsers.

Safari:

相关标签:
12条回答
  • 2020-11-30 19:25

    I didn't want to add more classes to fix this kind of bug, so alternatively you can fix the .row class itself.

    .row {
        &:before {
            content: none;
        }
    
        &:after {
            content: '';
        }
    } 
    
    0 讨论(0)
  • 2020-11-30 19:26

    I know the issue is quite old, but I ran into this issue today, and wasted over 12 hours in fixing it. Though about 10 hours out of that were spent in realizing that safari is failing with 12-column bootstrap grid, and it is no other issue.

    Fix that I made is rather simple. Here is the version for Visual Composer. Class names may vary for other frameworks.

    .vc_row-flex:before, .vc_row-flex:after{
      width: 0;
    }
    
    0 讨论(0)
  • 2020-11-30 19:30

    Just to update on my question

    This is the solution I go with, this is obviously fixed for Bootstrap4, which is flexbox compatible. So this is only for bootstrap3.

    .row.flexthis:after, .row.flexthis:before{
      display: none;
    }
    
    0 讨论(0)
  • 2020-11-30 19:31

    I was able to fix it by adding

    .row:before, .row:after {
    display: flex !important;
    }
    

    Obviously this isn't the most elegant solution but it may work for some in the meantime until they fix it.

    0 讨论(0)
  • 2020-11-30 19:37

    In case you are using display flex with flex-wrap i solved it applying a hight order to the before and after pseudo-elements of the row, so they position as the last elements.

    .row.flex_class {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .row.flex_class::before, .row.flex_class::after {
        order: 10;
    }
    
    0 讨论(0)
  • 2020-11-30 19:39

    I've spent a few hours on this issue as well. In my case I inserted flexbox in an existing project to make all elements in a row have the same height. All browsers except Safari rendered it correctly, but none of the above answers seemed to fix my problem.

    Until I discovered that there still was a Bootstrap clearfix hack being used: (code is from a laravel project, but generic Bootstrap otherwise)

    @foreach ($articles as $key => $article)
        @if ($key % 3 === 0)
            <div class="clearfix hidden-xs hidden-sm"></div>
        @endif
        @if ($key % 2 === 0)
            <div class="clearfix hidden-lg hidden-md"></div>
        @endif
    
        etc...
    @endforeach
    

    Apparently, other browsers than Safari ignore the .clearfix in some way when flexbox is being used.

    So, when using flexbox on your columns, there is no need to use Bootstrap's clearfix anymore.

    0 讨论(0)
提交回复
热议问题