SoFunction
Updated on 2025-02-28

Detailed explanation of the raster system of Bootstrap layout

I learned bootstrap a few days ago and sorted out the grid system. If there are any errors, please feel free to correct them.
Summary: The grid system has developed responsive web pages for PC, pad and mobile terminals, and there are different solutions based on different screen resolutions.
(0.1, screen device size is greater than 1200px Select col-lg
(0.2. Screen device size is between 970px and 1200px. Select col-md
(0.3. Screen device size is between 768px and 970px. Select col-sm
(0.4. Screen device size is less than 768px Select col-xs

1. The grid system divides the page into 12 columns (up to 12 columns), as follows: 

<!DOCTYPE html>
<html lang="zh-cn">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width,initial-scale=1,maxinum-scale,user-scalable=no">
 <title>Grid system</title>
 <link rel="stylesheet" href="library/">
 <style>
       .a{
        height: 50px;
        border: 1px red solid;
        background: pink;
       } 
 </style>
</head>
<body>
 <div class="container a">
  <div class="row">
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
   <div class="col-md-1 a">1</div>
  </div>

  <div class="row">
   <div class="col-md-3 a">3</div>
   <div class="col-md-9 a">9</div>
  </div>
 </div>


<script src="library/"></script> 
<script src="library/"></script>
</body>
</html>

(2.1, col-md-1 is a column, with a total of 12 columns covered with a "horizontal row". The number trailing after md is the number of columns assigned, (col-lg, col-sm, col-xs is the same)

3. Under devices with different screen resolutions, the page presented is the corresponding "raster format bar page", thereby realizing a responsive layout, as shown below

<!DOCTYPE html>
<html lang="zh-cn">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width,initial-scale=1,maxinum-scale,user-scalable=no">
 <title>Grid system</title>
 <link rel="stylesheet" href="library/">
 <style>
       .a{
        height: 50px;
        border: 1px red solid;
        background: pink;
       } 
 </style>
</head>
<body>
 <div class="container">
  <div class="row">
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
   <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>   
  </div>
 </div>

<script src="library/"></script> 
<script src="library/"></script>
</body>
</html>

(3.1. The code above shows that when the screen device size is greater than 1200px, one horizontal row has four columns, one large column has three small columns, and the small column has a total of 12 columns.
(3.2, indicating that when the screen device size is between 970px and 1200px (you can first look at the browser shrinking to this stage), there are three columns in a horizontal row, and four columns in a large column, with a total of 12 columns.
(3.2, indicating that when the screen device size is between 768px and 970px (you can first look at the browser shrinking to this stage), there are two large columns in a horizontal row, and six small columns in a large column, with a total of 12 columns.
(3.2, indicating that when the screen device size is less than 768px (you can first look at the browser shrinking to this stage), there is a large column in a horizontal row, and a large column has twelve small columns, with a total of 12 columns.

4. Column offset, nesting and swap positions in the raster system
(4.1, Column Offset

 <div class="row">   
    <div class="col-md-8 a">8</div>
    <div class="col-md-3 col-md-offset-1 a">3</div> <!-- The column is offset one by one to the right -->   
  </div> 

(4.2, nesting

 <div class="row">  <!-- Nesting -->  
   <div class="col-md-9 a" style="padding:0;">
    <div class="col-md-4 a"></div>
    <div class="col-md-4 a"></div>
    <div class="col-md-4 a"></div>
   </div>
   <div class="col-md-3 a">3</div>    
 </div>

(4.3, swap position

 <div class="row">   <!-- Switch location -->  
   <div class="col-md-9 col-md-push-3 a">9</div>   <!-- push,Move right -->
   <div class="col-md-3 col-md-pull-9 a">3</div>   <!-- pull,Move left -->
 </div>

If you want to learn more, you can clickhereLet’s study and attach 3 exciting topics to you:

Bootstrap learning tutorial

Bootstrap practical tutorial

Bootstrap plug-in usage tutorial

This article uses the simplest cases to analyze the key layout points involved in the case, hoping to be helpful to everyone's learning.