in Education by

Explain the basic structure of the Bootstrap grid.

1 Answer

0 votes
by

Now for creating rows and columns using 12 column responsive grid systems. 

  • First we need to create a container that acts as a wrapper for our rows and columns by using the .container class.
  • Then we have to create rows inside the container by using (<div class="row">) ,
  • Then we need to add the desired number of columns inside any row by using classes .col-xs-*, .col-sm-*, .col-md-* and .col-lg-* the number of columns should always add up to 12 for each row. In these columns we write our contents.

The following is a Basic Structure,

Basic Structure
 

  1. <div class="container">  
  2.     <div class="row">  
  3.         <div class="col-*-*">col1</div>  
  4.         <div class="col-*-*">col2</div>  
  5.         <div class="col-*-*">col3</div>  
  6.     </div>  
  7.     <div class="row">  
  8.         ...  
  9.     </div>  
  10. </div>  

Now we will create some examples for Grid Layouts by which we can easily make responsive website layouts.

Example 1

Two Column Layouts


In this example we will create two column layouts for different devices. In mobile the column will automatically arrange horizontally according to screen size. We know that grid system works on 12 columns, so for creating two column layouts we keep the sum of the grid column numbers equal to 12 in each row so columns will be in one line. In this example we will add three rows and inside each row we will add two columns. Let's create the example.

Step 1

First we will create a Bootstrap Template, HTML page named "TwoColLayout.html" by using the following code.

  1. <!DOCTYPE html>  
  2.   
  3. <html lang="en">  
  4.   
  5. <head>  
  6.     <meta charset="utf-8">  
  7.     <title>Bootstrap Part3</title>  
  8.     <meta name="viewport" content="width=device-width,initial-scale=1">  
  9.     <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">  
  10. </head>  
  11.   
  12. <body>  
  13.     <div class="container">  
  14.         <h1>Two Column Layouts</h1>  
  15.     </div>  
  16.     <script src="js/jquery-2.1.4.min.js"></script>  
  17.     <script src="js/bootstrap.min.js"></script>  
  18. </body>  
  19.   
  20. </html>  

Step 2

Now we will add rows and columns for creating Two Column Layouts by the following code; in this we will give style "background-color" for each column so output shows clearly.

  1. <!DOCTYPE html>  
  2.   
  3. <html lang="en">  
  4.   
  5. <head>  
  6.     <meta charset="utf-8">  
  7.     <title>Bootstrap Part3</title>  
  8.     <meta name="viewport" content="width=device-width,initial-scale=1">  
  9.     <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">  
  10. </head>  
  11.   
  12. <body>  
  13.     <div class="container">  
  14.         <h1>Two Column Layouts</h1>  
  15.         <!--First row with column number(4,8)-->  
  16.         <div class="row">  
  17.             <div class="col-sm-4" style="background-color:#8dc1aa">column1: col-sm-4</div>  
  18.             <div class="col-sm-8" style="background-color:#808080">column2: col-sm-8</div>  
  19.         </div>  
  20.         <!--Second row with column number(6,6)-->  
  21.         <div class="row">  
  22.             <div class="col-sm-6" style="background-color:#cfa6e2">column3: col-sm-6</div>  
  23.             <div class="col-sm-6" style="background-color:#faa76c">column4: col-sm-6</div>  
  24.         </div>  
  25.         <!--Third row with column number(3,9)-->  
  26.         <div class="row">  
  27.             <div class="col-sm-3" style="background-color:#c8fcfc">column5: col-sm-3</div>  
  28.             <div class="col-sm-9" style="background-color: #79ad96">column6: col-sm-9</div>  
  29.         </div>  
  30.     </div>  
  31.     <script src="js/jquery-2.1.4.min.js"></script>  
  32.     <script src="js/bootstrap.min.js"></script>  
  33. </body>  
  34.   
  35. </html>  

Output

See the output for different devices according to screen size.

Two Column Layouts

Related questions

0 votes
    Explain Bootstrap Grid System....
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Explain the Bootstrap basic table?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Explain Bootstrap buttons and its styles....
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Explain the use of Bootstrap CSS class="navnav-list"....
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    How can you give a style to images in Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    What are Containers in Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    What are the advantages of Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    How can we create a dropdown menu in Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    How can you create Fixed Layout with Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    How can you create a web page using Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    How can you get Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Why choose Bootstrap for building websites?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    What is Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    What do you understand about Responsive websites?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    I have a 9-cell grid containing images (using bootstrap columns). The grid works fine and is responsive ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
...