In the hope that you’ve previously read the Introduction to Flexbox theory, let’s get deeper into Rows.
Utilize breakpoint-specific column classes for equal-width columns. Add any number of unit-less classes for each breakpoint you need and every column will be the same width.
Equal-width
For example, here are two grid layouts that apply to every device and viewport, from xs to xl.
Setting one column width
Auto-layout for flexbox grid columns also means you can set the width of one column and the others will automatically resize around it. You may use predefined grid classes (as shown below) or inline widths. Note that the other columns will resize no matter the width of the center column.
Variable width content
Using the col-{breakpoint}-auto
classes, columns can size itself based on the natural width of its content. This is super handy with single line content like inputs, numbers, etc (see last example on this page). This, in conjunction with horizontal alignment classes, is very useful for centering layouts with uneven column sizes as viewport width changes.
Responsive classes
The grid includes five tiers of predefined classes for building complex responsive layouts. Customize the size of your columns on extra small, small, medium, large, or extra large devices however you see fit.
All breakpoints
For grids that are the same from the smallest of devices to the largest, use the .col
and .col-*
classes. Specify a numbered class when you need a particularly sized column; otherwise, feel free to stick to .col.
Stacked to horizontal
Using a combination of .col-12
and .col-md-*
classes, you can create a basic grid system that starts out stacked on small devices before becoming horizontal on desktop (medium) devices.
Mix and match
Don’t want your columns to simply stack in some grid tiers? Use a combination of different classes for each tier as needed. See the example below for a better idea of how it all works.
Alignment
Use flexbox alignment utilities to vertically and horizontally align columns.
TIP
There is also the convenience flex-center
CSS class which is equivalent to items-center
+ justify-center
. Use it along with flex
, row
or column
.
Column wrapping
If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.
Reordering
Offsetting columns
Move columns to the right using .offset-md-*
classes. These classes increase the left margin of a column by * columns. For example, .offset-md-4
moves .col-md-4
over four columns.
Nesting
To nest your content with the default grid, add a new .row and set of .col-sm-*
columns within an existing .col-sm-*
column. Nested rows should include a set of columns that add up to 12 or fewer (it is not required that you use all 12 available columns).
Flex Playground
To see the Flex in action, you can use the Flex Playground to interactively learn more.
Flex Playgroundlaunch