Bootstrap Grids
Below are some examples of basic Bootstrap grid layouts.
The following example demonstrates how to achieve three equal-width columns beginning with tablets and scaling to huge desktops. On mobile phones, the columns automatically stack:
.col-sm-3
.col-sm-6
.col-sm-3
The following example demonstrates how to create two columns of varying widths, beginning with tablets and scaling to huge desktops:
.col-sm-4
.col-sm-8
Use the .row-no-gutters class to remove the gutters from a row and its columns.
.col-sm-3
.col-sm-6
.col-sm-3
The following example demonstrates how to get two columns starting at tablets and scaling to huge desktops, with another two columns (equal widths) within the larger column (at mobile phones, these columns and their nested columns stack):
.col-sm-8
.col-sm-6
.col-sm-6
.col-sm-4
Bootstrap’s grid structure has four classes: xs (phones), sm (tablets), md (desktops), and lg (bigger desktops). Classes can be merged to create more dynamic and adaptable layouts.
Tip: Because each class scales up, you can define the same widths for xs and sm by specifying only xs.
.col-xs-9 .col-md-7
.col-xs-3 .col-md-5
.col-xs-6 .col-md-10
.col-xs-6 .col-md-2
.col-xs-6
.col-xs-6
Tip: Remember that grid columns should sum up to twelve per row. Columns will stack regardless of the viewport.
.col-xs-7 .col-sm-6 .col-lg-8
.col-xs-5 .col-sm-6 .col-lg-4
.col-xs-6 .col-sm-8 .col-lg-10
.col-xs-6 .col-sm-4 .col-lg-2
Clear floats (using the .clearfix class) at certain breakpoints to avoid unexpected wrapping with unequal content:
Column 1
Resize the browser window to see the effect.
Column 2
Column 3
Column 4
Columns can be moved to the right using the .col-md-offset-* class. These classes extend a column’s left margin by * columns.
.col-sm-5 .col-md-6
Change the order of the grid columns using the .col-md-push-* and .col-md-pull-* classes:
.col-sm-4 .col-sm-push-8
.col-sm-8 .col-sm-pull-4
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.