How to Customize Bootstrap Column Widths?

前端 未结 6 787
我在风中等你
我在风中等你 2020-12-05 02:23

I have this, but I feel 4 is too big for my sidebar width and 3 is too small (it has to add up to 12).

  
6条回答
  •  有刺的猬
    2020-12-05 02:44

    For a 12 columns grid, if you want to add half of a column (4,16667%) to each column width. This is what you do.

    For example, for col-md-X, define .col-md-X-5 with the following values.

    .col-md-1-5 { width: 12,5%; } // = 8,3333 + 4,16667
    .col-md-2-5 { width: 20,83333%; } // = 16,6666 + 4,16667
    .col-md-3-5 { width: 29,16667%; } // = 25 + 4,16667
    .col-md-4-5 { width: 37,5%; } // = 33,3333 + 4,16667
    .col-md-5-5 { width: 45,83333%; } // = 41,6667 + 4,16667
    .col-md-6-5 { width: 54,16667%; } // = 50 + 4,16667
    .col-md-7-5 { width: 62,5%; } // = 58,3333 + 4,16667
    .col-md-8-5 { width: 70,83333%; } // = 66,6666 + 4,16667
    .col-md-9-5 { width: 79,16667%; } // = 75 + 4,16667
    .col-md-10-5 { width: 87,5%; } // = 83,3333 + 4,16667
    .col-md-11-5 { width: 95,8333%; } // = 91,6666 + 4,16667
    

    I rounded certain values.

    Secondly, to avoid copying css code from the original col-md-X, use them in the class declaration. Be careful that they should be added before your modified ones. That way, only the width gets override.

    ...
    ...
    ...

    Finally, don't forget that the total should not exceed 12 columns, which total 100%.

    I hope it helps!

提交回复
热议问题