Bootstrap

Explain the Bootstrap Grid system


Introduction

Without being aware of the correct resources and not using them to create a user user-friendly and mobile-first website that works best on all the mobiles and desktops is a tedious task to get done. Here the bootstrap grid system comes into the picture. Developers may more easily organize material in ways that fluidly adjust to various screen sizes thanks to the Bootstrap Grid System, which streamlines the layout design process.

We'll go over the fundamentals of the Bootstrap Grid System in this blog post, along with its purpose, functionality and useful code samples to show how to apply it successfully in web applications.

Why Grid System?

Before Bootstrap, it took a lot of time and a thorough understanding of media queries to create a fluid, responsive layout, which frequently led to discrepancies between devices and browsers. This is resolved with Bootstrap's Grid System, which provides:

  1. Consistency: Prevents individual styling problems and guarantees a consistent layout across devices and browsers.

  2. Responsiveness: By default, the layout is mobile-friendly, automatically adjusting to the screen size.

  3. Ease of Use: By using predefined classes, developers may easily organize material without having to worry about intricate CSS rules.

  4. Flexibility: Gives developers the ability to choose how their material appears by supporting both fixed and fluid layouts.

The Bootstrap Grid System is a crucial tool for simplifying and improving responsive design, regardless of the size of the application or website you're creating.

How to Use Grid?

The 12-column layout that separates the webpage horizontally is the foundation of the Bootstrap Grid System. This technique divides each row into 12 columns, each of which can have its width changed according to the screen size.

The elements that make up the Bootstrap Grid are broken down as follows:

  1. Container: The primary wrapper that contains the rows and columns is called a container. Containers regulate the layout's maximum width.

  2. Row: Groups of columns arranged horizontally are called rows. They guarantee correct alignment and spacing, contain the columns, and arrange them.

  3. Column: You put your material in columns. They offer responsive design features because they can be easily resized according to the screen size.

Configuring the Grid System for Bootstrap

Make sure the Bootstrap CSS file is linked to your project before you begin using the grid system. You can utilize a CDN or download it. Here's how to use CDN to incorporate it:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.3.0/css/bootstrap.min.css">

 

You may begin working with containers, rows, and columns as soon as Bootstrap is included.

Guide on the Grid System for Bootstrap

Let us see some of the examples that explain how the Bootstrap’s grid system functions to create responsive and mobile first designs and layouts

1. Making a Basic Grid Design

Creating a container, adding rows, and then putting columns inside each row is the most basic grid configuration. This is a fundamental structure:

<div class="container"> <div class="row"> <div class="col">Column 1</div> <div class="col">Column 2</div> <div class="col">Column 3</div> </div></div>

 

In this instance:

  • The grid's primary container, which gives it a responsive width, is provided by the. Container class.
  • We utilize a.row to store the columns inside the container.
  • The available width is automatically distributed equally among the three columns by each. Col.

2. Using Custom Column Sizes to Create a Grid Layout

Assume that the first column should occupy half of the width, with the other two columns occupying a quarter each. This can be accomplished by utilizing the. Col-* classes to set column sizes, where * can be any integer between 1 and 12:

<div class="container"> <div class="row"> <div class="col-6">Column 1 (6/12)</div> <div class="col-3">Column 2 (3/12)</div> <div class="col-3">Column 3 (3/12)</div> </div></div>

 

Here:

  • Column 1 spans six of the twelve columns (or half of the row width) when col-6 is used.
  • Col-3 allocates the remaining two columns three of the twelve columns, or a quarter of the row width.

3. Adaptive Designs Using Bootstrap Grid

With classes like. Col-sm-*,.col-md-*, .col-lg-*, and. col-xl-*, you may specify multiple column sizes for various screen sizes using the Bootstrap Grid System. This guarantees that your layout adapts to variations in screen size.

For example:

<div class="container"> <div class="row"> <div class="col-12 col-md-8">Main Content</div> <div class="col-12 col-md-4">Sidebar</div> </div></div>

 

In this case,

  • col-12 indicates that each column will fill the row width for small screens (less than MD size).
  • The first column will occupy 8 columns on medium screens (md and up), while the second column will occupy 4 columns, resulting in a two-column arrangement.

4. Using Nesting Columns to Create More Intricate Designs

Even more intricate designs are made possible by Bootstrap's Grid System, which also lets you nest columns inside of other columns. Just use the same grid classes and add a new row inside a column.

For instance:

<div class="container"> <div class="row"> <div class="col-6"> Main Column <div class="row"> <div class="col-6">Inside Column One</div> <div class="col-6">Inside Column Two</div> </div> </div> <div class="col-6">Another Main Column</div> </div></div>

 

In this instance:

  • There are two primary columns in the main row.
  • We create a divide inside the first main column by adding a second row with two nested columns.

5. Columns That Offset

You may occasionally choose to leave some white space on either side of a column. The offset classes in Bootstrap can assist by moving columns to the right.

For instance:

<div class="container"> <div class="row"> <div class="col-4 offset-4">Centered Column</div> </div></div>

 

In this case, the offset-4 class centers the column in the row by pushing it four columns to the right.

Conclusion

The Bootstrap Grid System is a strong, adaptable framework that makes creating responsive layouts simple. Share your ideas in real-time. Without the need for complicated CSS, it provides a rational, organized method of dividing a web page into rows and columns that can adjust to various screen sizes. You can design layouts that look fantastic and offer a consistent user experience across devices by knowing how to employ containers, rows, columns and responsive classes.

Ready to transform your business with our technology solutions? Contact Us today to Leverage Our Bootstrap Expertise.


Bootstrap

Related Center Of Excellence