Ariel Rodriguez Romero

Modify Bootstrap's default grid system padding

Using Bootstrap column grid is extremely helpful, however they come with a default 30px margin between each column. This padding can be modified by changing the variable @grid-gutter-width, although sometimes its useful to be able to use different values of this padding.

That’s what this mixin does, allows the creation of a class to modify the padding within columns inside a row.

.row-padding(@padding) {
    margin-left: -@padding/2;
    margin-right: -@padding/2;

	.col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, 
	.col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, 
	.col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, 
	.col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, 
	.col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, 
	.col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, 
	.col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, 
	.col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, 
	.col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, 
	.col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, 
	.col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, 
	.col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 {
	    padding-left: @padding/2;
	    padding-right: @padding/2;
	}
}

Using it is pretty straightforward, just declare the class name and include the mixin.

.row--small {
	.row-padding(10px);
}

.row--large {
	.row-padding(50px);
}

And then on the html, add on the .row element as a modifier of this class.

<div class="row row--small">
	<div class="col-sm-4"></div>
	<div class="col-sm-4"></div>
	<div class="col-sm-4"></div>
</div>

<div class="row row--large">
	<div class="col-md-6"></div>
	<div class="col-md-6"></div>
</div>

Related posts

Hiding state, simplifying modal dialogs usages

Render props is a very powerful technique in React, here it’s applied to Modal Dialogs to simplify their usage. There’re examples with react-modal.

Problems with my laptop HP Envy 15t-as100

My laptop died suddenly after 19 months, I tried to fix it. This is the story.

Jekyll: Re-designing my personal blog.

Finally! I updated the blog. I talk about the entire process here.