Twitter Bootstrap - add top space between rows

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

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

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

    you can add this code :

    [class*="col-"] {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }
    
    0 讨论(0)
  • 2020-11-28 17:43

    I added these classes to my bootstrap stylesheet

    .voffset  { margin-top: 2px; }
    .voffset1 { margin-top: 5px; }
    .voffset2 { margin-top: 10px; }
    .voffset3 { margin-top: 15px; }
    .voffset4 { margin-top: 30px; }
    .voffset5 { margin-top: 40px; }
    .voffset6 { margin-top: 60px; }
    .voffset7 { margin-top: 80px; }
    .voffset8 { margin-top: 100px; }
    .voffset9 { margin-top: 150px; }
    

    Example

    <div class="container">
      <div class="row voffset2">
        <div class="col-lg-12">
          <p>
            Vertically offset text.
          </p>
        </div>
      </div>
    </div>
    
    0 讨论(0)
  • 2020-11-28 17:45

    Editing or overriding the row in Twitter bootstrap is a bad idea, because this is a core part of the page scaffolding and you will need rows without a top margin.

    To solve this, instead create a new class "top-buffer" that adds the standard margin that you need.

    .top-buffer { margin-top:20px; }
    

    And then use it on the row divs where you need a top margin.

    <div class="row top-buffer"> ...
    
    0 讨论(0)
  • 2020-11-28 17:45

    For Bootstrap 4 spacing should be applied using

    shorthand utility classes

    in the following format:

    {property}{sides}-{size}

    Where property is one of:

    • m - for classes that set margin
    • p - for classes that set padding

    Where sides is one of:

    • t - for classes that set margin-top or padding-top
    • b - for classes that set margin-bottom or padding-bottom
    • l - for classes that set margin-left or padding-left
    • r - for classes that set margin-right or padding-right
    • x - for classes that set both *-left and *-right
    • y - for classes that set both *-top and *-bottom
    • blank - for classes that set a margin or padding on all 4 sides of the element

    Where size is one of:

    • 0 - for classes that eliminate the margin or padding by setting it to 0
    • 1 - (by default) for classes that set the margin or padding to $spacer * .25
    • 2 - (by default) for classes that set the margin or padding to $spacer * .5
    • 3 - (by default) for classes that set the margin or padding to $spacer
    • 4 - (by default) for classes that set the margin or padding to $spacer * 1.5
    • 5 - (by default) for classes that set the margin or padding to $spacer * 3
    • auto - for classes that set the margin to auto

    So you should be doing any of these:

    <div class="row mt-1">
    <div class="row mt-2">
              ...
    <div class="row mt-5">
    

    Read the docs for more explanation. Try live examples over here.

    0 讨论(0)
  • 2020-11-28 17:46
    <div class="row row-padding">
    

    simple code

    0 讨论(0)
  • 2020-11-28 17:46
    just take a new class beside every row and apply css of margin-top: 20px;
    here is the code below
    <style>
      .small-top
       {
         margin-top: 25px;  
       }
    </style>    
    <div class="row small-top">
       <div class="col-md-12">
       </div>
     </div>
    
    0 讨论(0)
提交回复
热议问题