Bootstrap row class contains margin-left and margin-right which creates problems

前端 未结 8 2014
北恋
北恋 2020-12-02 15:20

I am using Bootstrap \'row\' class to align divs one on top of another, which works fine but

.row {
   margin-left: -15px;
   marg         


        
8条回答
  •  独厮守ぢ
    2020-12-02 15:50

    Old topic, but I think I found another descent solution. Adding class="row" to a div will result in this CSS configuration:

    .row {
        display: -webkit-box;
        display: flex;
        flex-wrap: wrap;
        margin-right: -15px;
        margin-left: -15px;
    }
    

    We want to keep the first 3 rules and we can do this with class="d-flex flex-wrap" (see https://getbootstrap.com/docs/4.1/utilities/flex/):

    .flex-wrap {
        flex-wrap: wrap !important;
    }
    .d-flex {
        display: -webkit-box !important;
        display: flex !important;
    }
    

    It adds !important rules though but it shouldn't be a problem in most cases...

提交回复
热议问题