Twitter Bootstrap - add top space between rows

前端 未结 19 2276
孤独总比滥情好
孤独总比滥情好 2020-11-28 17:17

How to add margin top to class=\"row\" elements using twitter bootstrap framework?

相关标签:
19条回答
  • 2020-11-28 17:57

    If you're using BootStrap 3.3.7, you can use the open source library bootstrap-spacer via NPM

    npm install bootstrap-spacer
    

    or you can visit the github page:

    https://github.com/chigozieorunta/bootstrap-spacer
    

    Here's an example of how this works to space rows using the .row-spacer class:

    <div class="row row-spacer">
        <div class="col-md-4">
        </div>
        <div class="col-md-4">
        </div>
        <div class="col-md-4">
        </div>
    </div>
    
    <div class="row row-spacer">
        <div class="col-md-4">
        </div>
        <div class="col-md-4">
        </div>
        <div class="col-md-4">
        </div>
    </div>
    

    If you'd require spaces between columns, you can also add the .row-col-spacer class:

    <div class="row row-col-spacer">
        <div class="col-md-4">
        </div>
        <div class="col-md-4">
        </div>
        <div class="col-md-4">
        </div>
    </div>
    

    And you can also combine various the .row-spacer & .row-col-spacer classes together:

    <div class="row row-spacer row-col-spacer">
        <div class="col-md-4">
        </div>
        <div class="col-md-4">
        </div>
        <div class="col-md-4">
        </div>
    </div>
    
    0 讨论(0)
  • 2020-11-28 17:57

    My trick. Not so clean, but works well for me

    <p>&nbsp;</p>
    
    0 讨论(0)
  • 2020-11-28 17:58

    In Bootstrap 4 alpha+ you can use this

    class margin-bottom-5
    

    The classes are named using the format: {property}-{sides}-{size}

    0 讨论(0)
  • 2020-11-28 17:58

    Just simply use this bs3-upgrade helper for spacings and text aligment...

    https://github.com/studija/bs3-upgrade

    0 讨论(0)
  • 2020-11-28 18:02

    Ok just to let you know what's happened then, i fixed using some new classes as Acyra says above:

    .top5 { margin-top:5px; }
    .top7 { margin-top:7px; }
    .top10 { margin-top:10px; }
    .top15 { margin-top:15px; }
    .top17 { margin-top:17px; }
    .top30 { margin-top:30px; }
    

    whenever i want i do <div class="row top7"></div>

    for better responsive you can add margin-top:7% instead of 5px for example :D

    0 讨论(0)
  • 2020-11-28 18:03

    Bootstrap 4 alpha, for margin-top: shorthand CSS class names mt-1, mt-2 ( mt-lg-5, mt-sm-2) same for the bottom, right, left, and you have also auto class ml-auto

        <div class="mt-lg-1" ...>
    

    Units are from 1 to 5 : in the variables.scss which means if you set mt-1 it gives .25rem of margin top.

    $spacers: (
      0: (
        x: 0,
        y: 0
      ),
      1: (
        x: ($spacer-x * .25),
        y: ($spacer-y * .25)
      ),
      2: (
        x: ($spacer-x * .5),
        y: ($spacer-y * .5)
      ),
      3: (
        x: $spacer-x,
        y: $spacer-y
      ),
      4: (
        x: ($spacer-x * 1.5),
        y: ($spacer-y * 1.5)
      ),
      5: (
        x: ($spacer-x * 3),
        y: ($spacer-y * 3)
      )
    ) !default;
    

    read-more here

    https://v4-alpha.getbootstrap.com/utilities/spacing/#horizontal-centering

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