Skip to main content

Archive

Show more

Bootstrap Grid System

Bootstrap Grid System

The Bootstrap grid system is a powerful layout tool that allows developers to create responsive and flexible web layouts. It is based on a 12-column grid layout system that adjusts and scales automatically based on the viewport size. Here's an overview of the Bootstrap grid system:


1. Container

Bootstrap grid layouts must be placed inside a container. Containers are the most basic layout element in Bootstrap and provide a consistent padding and margin around the content.

There are two types of containers:

  • .container: Creates a fixed-width container that is centered horizontally on the page.
  • .container-fluid: Creates a full-width container that spans the entire width of the viewport.

2. Rows

Inside the container, you can create rows to organize content horizontally. Rows are used to contain and clear the floated columns. Each row consists of one or more columns, and the total number of columns should not exceed 12 in a single row.


3. Columns

Columns are the building blocks of the Bootstrap grid system. They are used to create the layout of the content within a row. Bootstrap provides classes to define the width of columns at different breakpoints (extra small, small, medium, large, extra large).

Example:

<div class="container">
    <div class="row">
        <div class="col-md-6">
            Column 1
        </div>
        <div class="col-md-6">
            Column 2
        </div>
    </div>
</div>

In this example, each column occupies 50% of the container's width on medium-sized screens and above.


4. Column Ordering

Bootstrap allows you to change the order of columns using the .order-{breakpoint}-{order} classes. This allows for more flexibility in designing layouts for different screen sizes.

Example:

<div class="container">
    <div class="row">
        <div class="col-md-4 order-md-3">
            Column 1
        </div>
        <div class="col-md-4 order-md-1">
            Column 2
        </div>
        <div class="col-md-4 order-md-2">
            Column 3
        </div>
    </div>
</div>

In this example, the columns are ordered differently on medium-sized screens and above.


5. Example: Complete Grid Template

Below is an example of a complete grid layout template using Bootstrap:

<div class="container">
    <div class="row">
        <div class="col-md-4">
            Column 1
        </div>
        <div class="col-md-4">
            Column 2
        </div>
        <div class="col-md-4">
            Column 3
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
            Column 4
        </div>
        <div class="col-md-6">
            Column 5
        </div>
    </div>
</div>

Conclusion

The Bootstrap grid system provides a flexible and responsive layout framework for building modern web interfaces. By utilizing containers, rows, and columns, developers can create complex layouts that adapt seamlessly to different screen sizes and devices.

Comments