Bootstrap 3 Grid with No Gap

Bootstrap 3 grid with no gap

The grid system in Bootstrap 3 requires a bit of a lateral shift in your thinking from Bootstrap 2. A column in BS2 (col-*) is NOT synonymous with a column in BS3 (col-sm-*, etc), but there is a way to achieve the same result.

Check out this update to your fiddle: http://jsfiddle.net/pjBzY/22/ (code copied below).

First of all, you don't need to specify a col for each screen size if you want 50/50 columns at all sizes. col-sm-6 applies not only to small screens, but also medium and large, meaning class="col-sm-6 col-md-6" is redundant (the benefit comes in if you want to change the column widths at different size screens, such as col-sm-6 col-md-8).

As for the margins issue, the negative margins provide a way to align blocks of text in a more flexible way than was possible in BS2. You'll notice in the jsfiddle, the text in the first column aligns visually with the text in the paragraph outside the row -- except at "xs" window sizes, where the columns aren't applied.

If you need behavior closer to what you had in BS2, where there is padding between each column and there are no visual negative margins, you will need to add an inner-div to each column. See the inner-content in my jsfiddle. Put something like this in each column, and they will behave the way old col-* elements did in BS2.


jsfiddle HTML

<div class="container">
<p class="other-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse aliquam sed sem nec viverra. Phasellus fringilla metus vitae libero posuere mattis. Integer sit amet tincidunt felis. Maecenas et pharetra leo. Etiam venenatis purus et nibh laoreet blandit.</p>
<div class="row">
<div class="col-sm-6 my-column">
Col 1
<p class="inner-content">Inner content - THIS element is more synonymous with a Bootstrap 2 col-*.</p>
</div>
<div class="col-sm-6 my-column">
Col 2
</div>
</div>
</div>

and the CSS

.row {
border: blue 1px solid;
}
.my-column {
background-color: green;
padding-top: 10px;
padding-bottom: 10px;
}
.my-column:first-child {
background-color: red;
}

.inner-content {
background: #eee;
border: #999;
border-radius: 5px;
padding: 15px;
}

How to deal with Bootstrap 3 columns have no gap?

If you can't use the default padding to create gaps, you'd have to add `margin-left' to the appropriate columns and also tweak the % width.

For example .col-lg-4 usually has 33% width, so you'd decrease it a little..

.col-lg-4 {
margin-left:15px;
width:31.6%;
}

http://bootply.com/74374

Another option would be to use a container inside the columns, and then the padding will work to create the gaps.

Remove spacing between cols

add a class when you need to remove spaces use it

.padding-0{
padding-right:0;
padding-left:0;
}

in html write this class

<div class="row">
<div class="col-md-2 padding-0">
//stuff here for this column
</div>
<div class="col-md-10 padding-0">
//stuff here for columns
</div>
</div>

How to add no margin or padding between images using bootstrap 3?

Field of square images with no gaps between them

Attention! These solutions are not suitable for images of different heights.


1. HTML-tags are right close to each other

If your images have the same size, you can use even very forthright solution. I've placed all images into one row and removed spaces between them.

Don't forget to remove class img-responsive from images. This class adds a property display: block;. This property makes all the images stand in a column one above the other.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<div class="container-fluid">

<div class="row">

<div class="col-xs-12 text-center"><a

href="#"><img src="http://placehold.it/400x400/c69/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/9c6/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/69c/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/c96/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/6c9/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/96c/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/c69/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/9c6/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/69c/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/c96/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/6c9/fff/?text=Work" alt="Sample Image"></a><a

href="#"><img src="http://placehold.it/400x400/96c/fff/?text=Work" alt="Sample Image"></a></div>

</div>

</div>

Remove bottom gap in bootstrap column

just add my-auto since it's bootstrap

<div class="col-md-4 mx-auto text-center my-auto">
</div>

How to add spacing between columns?

You can achieve spacing between columns using the col-md-offset-* classes, documented here. The spacing is consistent so that all of your columns line up correctly. To get even spacing and column size I would do the following:

<div class="row">
<div class="col-md-5"></div>
<div class="col-md-5 col-md-offset-2"></div>
</div>

In Bootstrap 4 use: offset-2 or offset-md-2



Related Topics



Leave a reply



Submit