Learn about the Grid Tier System and Breakpoint features of Bootstrap v4

0
1090
grid-tier-system

In this article, we are going to explore the grid tier system and breakpoint feature of Bootstrap v4. The Grid system enables us to create advanced layouts by using the rows and columns. In Bootstrap v4 Grid system, we can create a maximum of 12 columns with the different viewport size specifications (e.g. mobile devices, laptop, tablets, etc.).

The following is an example of a Bootstrap grid:

Output
gridsystems
Explanation of code

  1. The first row has 12 columns and for each column, we have used the .col-xs-1 class. It means that, the xs column (extra small column) is going to occupy a single spot out of 12 spots in a row. Therefore, under the .row class, we have defined 12 such columns so that they occupy all the 12 spots for that row.
  2. In the 2nd row, we have defined 3 columns where 1st column occupies 2 spots, followed by 2nd column and third column which occupies 3 and 7 spots respectively.
  3. In the 3rd row, we have defined 4 columns of equal size with each column occupies 3 spots (i.e. .col-xm-3 class).
  4. In the 4th row, we have defined only a single column that occupies 12 spots (i.e. .col.xm-12 class).
  5. In the 5th row, we have defined 2 rows where the first column occupies 4 spots and the second column occupies 8 spots.
  6. In the 6th row, we have defined two columns of equal lengths of 6 spots each (i.e. .col-xm-6 class).

Grid Sizes
In the above example, we have used the column size as .col-xs-. In Bootstrap v4, there are total 5 column sizes are available. They are as follows.

  • Extra small (i.e. .col-xs-* class).
  • Small (i.e. .col-sm-* class).
  • Medium (i.e. .col-md-* class).
  • Large (i.e. .col-lg-* class).
  • Extra-large (i.e. .col-xl-* class).

Let’s compare the actual size and other features for each of the column type on how different grid options work with different viewport sizes in the following table.

FEATURES

Extra small <34em

Small ≥34em

Medium ≥48em

Large ≥62em

Extra-large ≥75em

Class

.col-xs-*

.col-sm-*

.col-md-*

.col-lg-*

.col-xl-*

Width of Container

None (auto)

34rem

45rem

60rem

72.25rem

Allowed columns

Max 12

Max 12

Max 12

Max 12

Max 12

Grid behavior

Always Horizontal

Collapsed to start, horizontal above the breakpoints.

Gutter width

30px (15px on each side of a column).

Column order

Yes

Yes

Yes

Yes

Yes

Nestable

Yes

Yes

Yes

Yes

Yes

Offsets

Yes

Yes

Yes

Yes

Yes

Interesting things to know about Grid Systems in Bootstrap v4

  • Containers: Grids should always be placed in the container either by using .container class or the .container-fluid class. This will help in the appropriate alignment and padding.
  • Rows & Columns: A row may contain from 1 column to the maximum of 12 columns. The width of the column is adjustable within the 12 spots for a row. The content is present in the columns which are immediate children of a row.
  • Padding: Padding is present for the columns. The interesting thing to note here is that the padding on the first and the last column is offset by a negative margin on the row.
  • What will happen when we place more than 12 columns per row? If we attempt to define more than 12 columns for a single row then the columns will wrap to a new line. For example, if we have defined two columns as .col-lg-9 and .col.lg-4 then the column with .col.lg-4 class will wrap to the next new line.
  • What will happen when we place less than 12 Columns per Row? It is not necessary to use all the 12 column spots in a row. Therefore, we can use any number of columns within the 12 column spots and if exceed that then it will be wrapped to the next line.
  • Grid Classes: We can apply Grid classes to the devices with their screen widths greater than or equal to the breakpoint sizes. Also, we can override these grid classes targeting the smaller devices. Therefore, when we use .col-xs-* class, it will not only affect the devices with extra small viewport but also the small, medium and large devices viewports (unless we have defined viewport sizes via media query for a col-sm-*, col-md-* and/or col-lg-*).
  • Multiple Classes: We can use multiple classes in collaboration for a given element. E.g. we can use class=”col-sm-9 col-md-5″ in order to specify 9 columns for small viewports and 5 columns for medium and large viewports.

Medium Sized Device Columns, Grid Class Override and Multiple Classes
In the following example, we are going to use .col-md-* for medium sizes view ports which will override large and extra-large sized viewports as well. Also, we are using multiple classes to define the column spots for a row depending on the size of the devices’ viewport.

Output
gridsystems2

Conclusion:
In this article, we discussed the popular grid system and its interesting features for Bootstrap v4 along with demo examples.

LEAVE A REPLY

Please enter your comment!
Please enter your name here