Bootstrap grid is a powerful system for building mobile-first layouts. It's very extensive tool with a great number of options. Below we present you the core knowledge. It's a simplified overview of the most commonly used examples.
Basic exampleBootstrap’s grid system uses a series of containers, rows, and columns to layout and align content. It’s built with flexbox and is fully responsive. Below is an example and an in-depth explanation for how the grid system comes together.
One of three columns
One of three columns
One of three columns
The above example creates three equal-width columns across all devices and viewports using our predefined grid classes. Those columns are centered in the page with the parent MDBContainer
.
Taking it step by step:
ContainerBootstrap requires a containing element to wrap site contents and house our grid system. Without a container, the grid won't work properly.
RowRows create horizontal groups of columns. Therefore, if you want to split your layout horizontally, use MDBRow
.
Bootstrap's grid system allows up to 12 columns across the page.
We use MDBCol
to create a column. You can customize columns with properties, e.g. md="*"
, where *
specifies the number of columns between 1 and 12.
Attribute md
specifies the breakpoint where the columns change its width.
Attribute md
means "screen ≥768px", so in the example below the columns will stretch to 100% of the width on the screens smaller or equal 768px.
Breaking it down, here’s how the grid system comes together:
Our grid supports six responsive breakpoints. Breakpoints are based on min-width
media queries, meaning they affect that breakpoint and all those above it (e.g., sm="4"
applies to sm
, md
, lg
, xl
, and xxl
). This means you can control container and column sizing and behavior by each breakpoint.
Containers center and horizontally pad your content. Use MDBCol
for a responsive pixel width, property fluid
for width: 100%
across all viewports and devices, or a responsive container (e.g., property md
) for combination of fluid and pixel widths.
Rows are wrappers for columns. Each column has horizontal padding
(called a gutter) for controlling the space between them. This padding
is then counteracted on the rows with negative margins to ensure the content in your columns is visually aligned down the left side. Rows also support modifier classes to uniformly apply column sizing and gutter classes to change the spacing of your content.
Columns are incredibly flexible. There are 12 template columns available per row, allowing you to create different combinations of elements that span any number of columns. Column classes indicate the number of template columns to span (e.g., col="4"
spans four). width
s are set in percentages so you always have the same relative sizing.
Gutters are also responsive and customizable. Gutter classes are available across all breakpoints, with all the same sizes as our margin and padding spacing. Change horizontal gutters with .gx-*
classes, verical gutters with .gy-*
, or all gutters with .g-*
classes. .g-0
is also availble to remove gutters.
Sass variables, maps, and mixins power the grid. If you don’t want to use the predefined grid classes in Bootstrap, you can use our grid’s source Sass to create your own with more semantic markup. We also include some CSS custom properties to consume these Sass variables for even greater flexibility for you.
A few of the most common grid layout examples to get you familiar with building within the Bootstrap grid system.
Five grid tiersThere are five tiers to the Bootstrap grid system, one for each range of devices we support. Each tier starts at a minimum viewport size and automatically applies to the larger devices unless overridden.
Three equal columnsGet three equal-width columns starting at desktops and scaling to large desktops. On mobile devices, tablets and below, the columns will automatically stack.
Three unequal columnsGet three columns starting at desktops and scaling to large desktops of various widths. Remember, grid columns should add up to twelve for a single horizontal block. More than that, and columns start stacking no matter the viewport.
Two columnsGet two columns starting at desktops and scaling to large desktops.
Two columns with two nested columnsPer the documentation, nesting is easy—just put a row of columns within an existing column. This gives you two columns starting at desktops and scaling to large desktops, with another two (equal widths) within the larger column.
At mobile device sizes, tablets and down, these columns and their nested columns will stack.
Mixed: mobile and desktopThe Bootstrap v5 grid system has five tiers of classes: xs (extra small, this class infix is not used), sm (small), md (medium), lg (large), and xl (extra large). You can use nearly any combination of these classes as a component property to create more dynamic and flexible layouts.
Each tier of classes scales up, meaning if you plan on setting the same widths for md, lg and xl, you only need to specify md.
col="6" md="4"
col="6" md="4"
col="6" md="4"
Mixed: mobile, tablet, and desktopsm="6" lg="8"
col="6" lg="4"
col="6" sm="4"
col="6" sm="4"
col="6" sm="4"
ContainersAdditional properties added to MDBContainer
allow containers that are 100% wide until a particular breakpoint.
(100% width below 540px)
sm (100% width below 540px)
md (100% width below 720px)
lg (100% width below 960px)
xl (100% width below 1140px)
xxl (100% width below 1320px)
fluid (always 100% width)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4