In previous lessons, we covered the fundamentals of Bootstrap, such as its structure and use of containers. These concepts have prepared us to dive deeper into creating responsive layouts. In this lesson, we'll focus on another crucial feature of Bootstrap: the Grid System.
The Bootstrap Grid System is essential for creating responsive web designs. By the end of this lesson, you'll be able to:
Here's a preview of a part of the code we'll be working with:
HTML, XML1<div class="row"> 2 <div class="col-md-4"> 3 <h2>Corgi Fact 1</h2> 4 <p>Corgis were originally bred for herding cattle, sheep, and horses.</p> 5 </div> 6 <div class="col-md-4"> 7 <h2>Corgi Fact 2</h2> 8 <p>Queen Elizabeth II has owned more than 30 Corgis during her reign.</p> 9 </div> 10 <div class="col-md-4"> 11 <h2>Corgi Fact 3</h2> 12 <p>Corgis have a strong association with Welsh folklore.</p> 13 </div> 14</div>
Bootstrap’s grid system relies on a structure composed of containers, rows, and columns to organize and align content seamlessly. Here’s a basic example:
HTML, XML1<div class="container"> 2 <div class="row"> 3 <div class="col-sm"> 4 One of three columns 5 </div> 6 <div class="col-sm"> 7 One of three columns 8 </div> 9 <div class="col-sm"> 10 One of three columns 11 </div> 12 </div> 13</div>
In this example:
container
class provides a responsive fixed-width container.row
class creates a horizontal group of columns.col-sm
class indicates that the columns should span multiple columns on small devices and grow equally to fill the row. Other common sizes include col-xs
, col-md
, col-lg
, and col-xl
.This setup will result in three equally sized columns, side by side, that adjust their width based on the screen size.
The Bootstrap Grid System is crucial because it allows web developers to create flexible and responsive layouts quickly and efficiently. Here’s why mastering it is important:
Exciting, right? Let's start the practice section and explore how to implement this grid system in your projects.