Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Bootstrap 4, how to change inner $grid-gutter-width depending to breakpoints?

I'm currently working on Bootstrap4 in SCSS.

I want to change the inner $grid-gutter-width on smartphone only.

According to _grid.scss

$grid-columns: 12 !default; $grid-gutter-width: 30px !default;

On the bootstrap site, it is sait that :

Updated grid sizes, mixins, and variables. Grid gutters now have a Sass map so you can specify specific gutter widths at each breakpoint.

I can't find the map and how it can be done.

like image 405
Zorkzyd Avatar asked Mar 15 '18 15:03

Zorkzyd


People also ask

How do I change the width of a gutter in Bootstrap 4?

The Bootstrap grid allows 12 columns with 30 px wide gutters by default, but these numbers can be adjusted. Just check the Grid System block on the Customize page. The @grid-columns field allows to set a different number of columns, and the @grid-gutter-width field lets you change the gutter width.

How do I reduce the gutter space in Bootstrap?

The gutters between columns in our predefined grid classes can be removed with .g-0 . This removes the negative margin s from .row and the horizontal padding from all immediate children columns.

What is gutter width in Bootstrap?

In Bootstrap 4, There are 12 columns in the grid system each column has a small space in between that space is known as gutter space. Gutter Space has width 30px (15px on each side of a column).


2 Answers

This looks like a mistake in the docs. There used to be a map, but it was removed before 4.0.0 was released. However, it would be fairly easy to add this for just xs with SASS. For example 5px on mobile...

@media (min-width: map-get($grid-breakpoints, xs)) and (max-width: map-get($grid-breakpoints, sm)){
    .row > .col,
    .row > [class*="col-"] {
      padding-right: 5px;
      padding-left: 5px;
    }
}

https://www.codeply.com/go/XgynFzTmGv

like image 130
Zim Avatar answered Sep 23 '22 19:09

Zim


Same as Zim's answer but with the row fix and using the $grid-gutter-width variable. 10% nicer if you are using a preprocessor.

UPDATE: I added more styling to preserve the functionality of .no-gutters, which was broken before.

// HALF GUTTER WIDTH ON XS
@media (max-width: map-get($grid-breakpoints, sm)){
    .row:not(.no-gutters) {
        margin-right: -$grid-gutter-width / 4;
        margin-left: -$grid-gutter-width / 4;
    }
    .row:not(.no-gutters) > .col,
    .row:not(.no-gutters) > [class*="col-"] {
        padding-right: $grid-gutter-width / 4;
        padding-left: $grid-gutter-width / 4;
    }
}
like image 37
Arajay Avatar answered Sep 22 '22 19:09

Arajay