How to Change Default Bootstrap Fluid Grid 12 Column Gutter Width

前端 未结 3 788
我寻月下人不归
我寻月下人不归 2020-12-13 05:00

I am looking to know if there is any simple solution known to change the gutter with on the fluid default 12 grid bootstrap system (2.3.0).

3条回答
  •  北海茫月
    2020-12-13 05:10

    I was looking for a simple solution for this problem, too. My goal was to use simple CSS, not LESS. This answer as like any other i found, based on compiling LESS or using the online compiler of bootstrap. So i tried to find my own solution.

    Reading the documentation you will find the following about the gutter-width: Columns create gutters (gaps between column content) via padding. That padding is offset in rows for the first and last column via negative margin on .rows.

    Based on this i tried the following:

    .container {padding-left:1px;padding-right:1px;}
    .row {margin-left:-1px;margin-right:-1px;}
    .row > div {padding-left:1px;padding-right:1px;}
    

    From now the gutter width was only 2 pixel. My next problem was, that my intended width was an odd number. My solution was to remove the paddings and margins on the left and put them completely on the right:

    .container {padding-left:0;padding-right:5px;}
    .row {margin-left:0;margin-right:-5px;}
    .row > div {padding-left:0;padding-right:5px;}
    

    Now i have a 5 pixel gutter width.

    I did not tested this in all possible scenarios you can use bootstrap. Especially you have to pay attention to use only column-div's inside a row-div inside a container-div. But in my case it was a very effective solution without touching the origin source code of bootstrap or using a LESS compiler.

提交回复
热议问题