Twitter Bootstrap - add top space between rows

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

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

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

    Bootstrap3

    CSS (gutter only, without margins around):

    .row.row-gutter {
      margin-bottom: -15px;
      overflow: hidden;
    }
    .row.row-gutter > *[class^="col"] {
      margin-bottom: 15px;
    }
    

    CSS (equal margins around, 15px/2):

    .row.row-margins {
      padding-top: 7px; /* or margin-top: 7px; */
      padding-bottom: 7px; /* or margin-bottom: 7px; */
    }
    .row.row-margins > *[class^="col"] {
      margin-top: 8px;
      margin-bottom: 8px;
    }
    

    Usage:

    <div class="row row-gutter">
        <div class="col col-sm-9">first</div>
        <div class="col col-sm-3">second</div>
        <div class="col col-sm-12">third</div>
    </div>
    

    (with SASS or LESS 15px could be a variable from bootstrap)

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

    I'm using these classes to alter top margin:

    .margin-top-05 { margin-top: 0.5em; }
    .margin-top-10 { margin-top: 1.0em; }
    .margin-top-15 { margin-top: 1.5em; }
    .margin-top-20 { margin-top: 2.0em; }
    .margin-top-25 { margin-top: 2.5em; }
    .margin-top-30 { margin-top: 3.0em; }
    

    When I need an element to have 2em spacing from the element above I use it like this:

    <div class="row margin-top-20">Something here</div>
    

    If you prefere pixels so change the em to px to have it your way.

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

    Add to this class in the .css file:

    .row {
        margin-left: -20px;
        *zoom: 1;
        margin-top: 50px;
    }
    

    or make a new class and add it to the element

    .rowSpecificFormName td {
        margin-top: 50px;
    }
    
    0 讨论(0)
  • 2020-11-28 17:54

    You can use the following class for bootstrap 4:

    mt-0 mt-1 mt-2 mt-3 mt-4 ...

    Ref: https://v4-alpha.getbootstrap.com/utilities/spacing/

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

    If you want to change just on one page, add the following style rule:

     #myCustomDivID .row {
         margin-top:20px;
     }
    
    0 讨论(0)
  • 2020-11-28 17:55

    Bootstrap 3

    If you need to separate rows in bootstrap, you can simply use .form-group. This adds 15px margin to the bottom of row.

    In your case, to get margin top, you can add this class to previous .row element

    <div class="row form-group">
    
    /* From bootstrap.css */
    .form-group {
            margin-bottom: 15px;
    }
    

    Bootstrap 4

    You can use built-in spacing classes

    <div class="row mt-3"></div>
    

    The "t" in class name makes it apply only to "top" side, there are similar classes for bottom, left, right. The number defines space size.

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