Bootstrap columns work on the basis of a bootstrap 12 column grid template. These columns are placed within a row. These columns could be aligned, ordered, and offset.
Flexbox alignment utilities is very useful to align column either vertically or horizontally.
.align-items-start
inside .row
class.
.align-items-center
inside .row
class.
.align-items-end
inside .row
class.
General Syntax
<div class="container">
<div class="row align-items-start">
<div class="col">
First Column
</div>
</div>
</div>
Source Code
<div class="container bg-light mt-5">
<div class="row align-items-start" style="height: 100px;">
<div class="col bg-warning">
First Column
</div>
<div class="col bg-danger">
Second columns
</div>
<div class="col bg-warning">
Third columns
</div>
</div>
</div>
Try it yourself
Source Code : Output
Note:In this example .align-items-start
is used to align all the column at the top of container.
General Syntax
<div class="container">
<div class="row align-items-center">
<div class="col">First Column</div>
</div>
</div>
<!--/container-->
Source Code
<div class="container bg-light">
<div class="row align-items-center" style="height: 100px;">
<div class="col bg-warning text-center">First Column</div>
<div class="col bg-danger text-center">Second columns</div>
<div class="col bg-warning text-center">Third columns</div>
</div>
</div>
<!--/container-->
Try it yourself
Source Code : Output
Note:
In this example, .align-items-center
is used to align all the columns at the center of the container.
Source Code
<div class="container bg-light">
<div class="row align-items-end" style="height: 100px;">
<div class="col bg-warning">First Column</div>
<div class="col bg-danger">Second columns</div>
<div class="col bg-warning">Third columns</div>
</div>
</div>
Try it yourself
Source Code : Output
Note: In this example, .align-items-end
is used to align all the columns at the bottom of the container.
.align-self-start
inside .row
class.
.align-self-center
inside .row
class.
.align-self-end
inside .row
class.
Source Code
<div class="container bg-light">
<div class="row" style="height: 100px;">
<div class="col align-self-start bg-warning">First Column</div>
<div class="col align-self-center bg-danger">Second Column</div>
<div class="col align-self-end bg-warning">Third column</div>
</div>
</div>
Try it yourself
Source Code : Output
Note: In this example,.align-self-start
, .align-self-center
,.align-self-end
is used to place container's child element to top,center & bottom respectively.This alignment process happens vertically on y-axis.
Aligning starts from the left side of the container on the horizontal axis or x-axis.
General Syntax
<div class="row justify-content-start">
<div class="col-4">
First Column of the existing row
</div>
<div class="col-4">
Second Column of the existing row
</div>
</div>
<!--/row-->
Source Code
<div class="container bg-light">
<div class="row justify-content-center">
<div class="col-4 bg-warning p-4">
First Column of the existing row
</div>
<div class="col-4 bg-danger p-4">
Second Column of the existing row
</div>
</div>
</div>
Try it yourself
Source Code : Output
Note:
Please keep in mind that .justify-content-start
is used to align the container's child elements along the x-axis or horizontal axis from the start.
Source Code
<div class="container bg-light">
<div class="row justify-content-center">
<div class="col-4 bg-warning p-4">
First Column of the existing row
</div>
<div class="col-4 bg-danger p-4">
Second Column of the existing row
</div>
</div>
</div>
Try it yourself
Source Code : Output
Note: Please keep in mind that .justify-content-center
is used to align all the column or children elements of the row to the center of the x-axis or horizontal axis.
Source Code
<div class="container bg-light">
<div class="row justify-content-end">
<div class="col-4 p-4 bg-danger">
First Column of the existing row
</div>
<div class="col-4 p-4 bg-warning">
Second Column of the existing row
</div>
</div>
</div>
Try it yourself
Source Code : Output
Note:Please keep in mind that .justify-content-end
is used to align all the column or children elements of the row to the end of the container horizontally.
If any row contains more than 12 columns within a single row then extra column is considered as one unit and wrap into a new line.
If the summation of all column rows is less than or equal to twelve then it places into the first-row line and the rest is placed into the second line of the row if the sum of all the columns is less than or equal to twelve columns.
Source Code
<div class="container bg-light">
<div class="row">
<div class="col-9 p-4 bg-warning p-4">.col-9</div>
<div class="col-4 bg-danger p-4">.col-4<br /></div>
</div>
</div>
Try it yourself
Source Code : Output
Breaking columns to a new line in flexbox requires an element with a width of 100%.
Source Code
<div class="container bg-light">
<div class="row">
<div class="col-6 col-sm-3 p-4 bg-warning">.col-6 .col-sm-3</div>
<div class="col-6 col-sm-3 p-4 bg-danger">.col-6 .col-sm-3</div>
<!-- Force next columns to break to new line -->
<div class="w-100"></div>
<div class="col-6 col-sm-3 p-4 mt-4 bg-warning">.col-6 .col-sm-3</div>
<div class="col-6 col-sm-3 p-4 mt-4 bg-danger">.col-6 .col-sm-3</div>
</div>
</div>
Try it yourself
Source Code : Output
Column break can be applied at a specific breakpoint.
Source Code
<div class="container bg-light">
<div class="row">
<div class="col-6 col-sm-4 p-4 bg-warning">.col-6 .col-sm-4</div>
<div class="col-6 col-sm-4 p-4 bg-danger">.col-6 .col-sm-4</div>
<!-- Force next columns to break to new line at md breakpoint and up -->
<div class="w-100 d-none d-md-block"></div>
<div class="col-6 col-sm-4 p-4 bg-warning mt-4">.col-6 .col-sm-4</div>
<div class="col-6 col-sm-4 p-4 bg-danger mt-4">.col-6 .col-sm-4</div>
</div>
</div>
Try it yourself
Source Code : Output
Note:In the above example,column break concept is mention based on specfic device breakpoint.
To order the visual content, use .order class. You can also apply it at a specific breakpoint(e.g., .order-1,.order-md-2).
Source Code
<div class="container bg-light">
<div class="row">
<div class="col order-2 p-4 bg-danger">
First column without order
</div>
<div class="col order-5 p-4 bg-warning">
Second in DOM, with a larger order
</div>
<div class="col order-1 p-4 bg-danger">
Third in DOM, with an order of 1
</div>
</div>
</div>
Try it yourself
Source Code : Output
Note:
In the above example,row's child element can be ordered by providing .order-*
or .order-{xs/sm/md/xl/xxl}-*
to the child element base class.
The offset columns work on the basis of the left margin that will be generated by the column whenever applied offset to a specific column.
Offset classes is generally applied on the specific column using .offset-md-*
classes. to generate left margin of a column by *
columns.For example, .offset-md-4
moves .col-md-4
over four columns.
Source Code
<div class="container bg-light">
<div class="row">
<div class="col-md-3 p-4 bg-light">.col-md-3</div>
<div class="col-md-3 offset-md-3 p-4 bg-danger">.col-md-3 .offset-md-3</div>
</div>
<div class="row">
<div class="col-md-3 offset-md-3 p-4 bg-info">.col-md-3 .offset-md-3</div>
<div class="col-md-3 offset-md-3 p-4 bg-alert">.col-md-3 .offset-md-3</div>
</div>
<div class="row">
<div class="col-md-8 offset-md-2 p-4 bg-success">.col-md-8 .offset-md-2</div>
</div>
</div>
Try it yourself
Source Code : Output
Note:In the above example, column offset concept is used.