How can I remove the 30px gutter between columns? But without setting margin-left:-30px
?
<div class='container'> <div class='row'> <div class='col-lg-1'></div> <div class='col-lg-1'></div> <div class='col-lg-1'></div> </div> </div>
By default, Bootstrap 4 has class=”no-gutters” to remove gutter spaces of any specific div. The following image shows the highlighted gutter space and space between columns on bootstrap 4 12 column grid system. You can even modify gutter width by reducing 15px width of gutter space between each columns.
You can add new class to your div elements and remove padding/margin with css. To make it more clear, bootstrap assigns margin-left: -15px and margin-right: -15px for . row selector and padding-left: 15px and padding-right: 15px on all . col-* selectors to get 30px space between all the cols.
Update 2021
Bootstrap 5 the .no-gutters
class has been replaced with .g-0
. Use it on the .row
where you want no spacing between columns.
Bootstrap 5 also has new gutter classes that are specifically designed to adjust the gutter for the entire row. The gutters classes can be used responsively for each breakpoint (ie: gx-sm-4
)
g-0
for no guttersg-(1-5)
to adjust horizontal & vertical gutters via spacing unitsgy-*
to adjust vertical guttersgx-*
to adjust horizontal guttersBootstrap 4 now includes a .no-gutters
class that you can just add to the .row
.
<div class="row no-gutters"> <div class="col">x</div> <div class="col">x</div> <div class="col">x</div> </div>
Bootstrap 4: http://codeply.com/go/OBW3RK1ErD
Bootstrap 3.4.0+ gutters are created using padding, but they added a .row-no-gutters
class. See the documentation for Bootstrap 3.4 and look for 'Remove gutters'.
HTML you can use:
<div class="row row-no-gutters"> <div class="col">x</div> <div class="col">x</div> <div class="col">x</div> </div>
Bootstrap 3+, <= 3.3.9 gutters are created using padding. You also must adjust the negative margin so that spacing around the outer columns is not affected.
.no-gutter { margin-right: 0; margin-left: 0; } .no-gutter > [class*="col-"] { padding-right: 0; padding-left: 0; }
Just add the no-gutter
class to the .row
.
Demo: http://bootply.com/107458
A better way to remove padding on the columns would be to add a .no-pad
class to your .row
:
<div class="row no-pad">
...and then add this CSS.
.row.no-pad { margin-right:0; margin-left:0; } .row.no-pad > [class*='col-'] { padding-right:0; padding-left:0; }
It's a bad idea to look for first-
and last-child
items as actually the .row
is meant to take care of those offsets at the viewport's right and left. With the above method all .col-*
s remain identically styled, which is also much simpler when considering responsiveness, especially stacking at mobile sizes (try my demo below md
size).
The direct-descendant CSS selector >
means that the .no-pad
will only be applied to that .row
's immediate child .col
s, so you can have padding on subsequently nested column structures (or not) if you wish.
Also using the attribute selector [class*='col-']
means that each column needs no extra non-Bootstrap classes added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With