in Education by

What are Containers in Bootstrap?

1 Answer

0 votes
by

In Bootstrap we can contain elements to wrap site contents.

There are two Bootstrap Container classes,

  1. The .container class used to provide a responsive fixed width container.
  2. The .container-fluid class used to provide a full width container.

We have to note that we cannot put a container inside another container since it is not nestable.

Example 1

Using .container class (responsive fixed width container)


In this example we will create a simple Bootstrap page. Using ".container" class we will create a fixed width container that is responsive for different devices. In this we will write some text. We will have some space on the left and right side of the page by writing the following code.

  1. <!DOCTYPE html>  
  2.   
  3. <html lang="en">  
  4.   
  5. <head>  
  6.     <meta charset="utf-8">  
  7.     <title>Bootstrap Part2</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>This Is Bootstrap Page With Responsive Fixed Width Container</h1>  
  15.         <p>This Container Show Output Of Using (.container) Class</p>  
  16.     </div>  
  17.     <script src="js/jquery-2.1.4.min.js"></script>  
  18.     <script src="js/bootstrap.min.js"></script>  
  19. </body>  
  20.   
  21. </html>  

Output

container

responsive fixed width container

Example 2

Using .container-fluid class (full width container)

In this example we will create a simple Bootstrap page like Example 1. Using ".container-fluid"class we will create a full width container. In this we will write some text. Now we will create a page by writing the following code.

  1. <!DOCTYPE html>  
  2.   
  3. <html lang="en">  
  4.   
  5. <head>  
  6.     <meta charset="utf-8">  
  7.     <title>Bootstrap Part2</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-fluid">  
  14.         <h1>This Is Bootstrap Page With Full Width Container</h1>  
  15.         <p>This Container Show Output Of Using (.container-fluid) Class</p>  
  16.     </div>  
  17.     <script src="js/jquery-2.1.4.min.js"></script>  
  18.     <script src="js/bootstrap.min.js"></script>  
  19. </body>  
  20.   
  21. </html>  

Output

check output

Related questions

0 votes
    What are the advantages of Bootstrap?...
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
    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 basic structure of the Bootstrap grid....
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
    Explain Bootstrap Grid System....
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
    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
    How are Persistent volumes different from the Volumes used by containers (1)they are more Persistent (2)None of these (3)They ... than that of Pods (4)They do not have a lifecycle...
asked Sep 19, 2021 in Education by JackTerrance
...