Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap grid margin

I have a jsfiddle here: http://jsfiddle.net/nH5WP/

It's a super simple 3 x 3 grid using Bootstrap 3

I want to add margins to the right and bottom of each block.

The last block in each line is dropping down, I would normally remove the right margin on the last block in each line with something like

.box:last-child{
  background: yellow;
  margin: 0 0 10px 0;
}

but this doesn't seem to work.

How can I add margins between each block in this grid ?

<div class="container">

    <div class="row">
        <div class="col-xs-4 box">
            <p>One</p>
        </div>
        <div class="col-xs-4 box">
            <p>Two</p>
        </div>
        <div class="col-xs-4 box">
            <p>Three</p>
        </div>
    </div>

    <div class="row">
        <div class="col-xs-4 box">
            <p>Four</p>
        </div>
        <div class="col-xs-4 box">
            <p>Five</p>
        </div>
        <div class="col-xs-4 box">
            <p>Six</p>
        </div>
    </div>

    <div class="row">
        <div class="col-xs-4 box">
            <p>Seven</p>
        </div>
        <div class="col-xs-4 box">
            <p>Eight</p>
        </div>
        <div class="col-xs-4 box">
            <p>Nine</p>
        </div>
    </div>

</div>
like image 939
ttmt Avatar asked Jun 21 '14 09:06

ttmt


People also ask

How do I add a margin to a Bootstrap row?

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.

Is Bootstrap always 12 columns?

Bootstrap uses a 12-column grid system that can update itself responsively based on screen size. There are only 38 highly composite numbers below the one million threshold, including 120, 2520, 5040, 55440 and 720720. Such numbers rarely elbow their way into our everyday vernacular.


2 Answers

You can't create a "gutter" in the bootstrap grid system using margin:.

Bootstrap uses padding to build gutters, so you need to put a wrapper div around your columns and pads that.

See How to adjust gutter in Bootstrap 3 grid system? for more information.

like image 90
Peter Wooster Avatar answered Sep 22 '22 08:09

Peter Wooster


Apply width:calc(33.33% - 10px); in box class.

like image 26
Gus Avatar answered Sep 23 '22 08:09

Gus