DEV Community

Cover image for Day 2 Bootstrap 5 Basic layout and container
Brijesh Dobariya
Brijesh Dobariya

Posted on • Updated on

Day 2 Bootstrap 5 Basic layout and container

After introduction and installation of Bootstrap 5, we switch on to basic layout. In a layout section includes:

• Container

• Grid

• Gutters

• Columns

These are the most essential layout of bootstrap 5. In these tutorials we have brief discuss about container of Bootstrap.

Containers

Container is used to set the content's margins dealing with the responsive behaviours of your layout. It contains the row elements and the row elements are the container of columns (known as grid system).

How container works:

Containers are the most basic layout element in Bootstrap and are required when using our default grid system.

Containers are used to contain, pad, and (sometimes) center the content within them. While containers can be nested, most layouts do not require a nested container.

Containers are used to pad the content inside of them, and there are two container classes available:

The .container class provides a responsive fixed width container.

The .container-fluid class provides a full width container, spanning the entire width of the viewport

1) Fixed container

Use the .container class to create a responsive, fixed-width container.

Here is example of fixed container:

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap demo</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor"crossorigin="anonymous">
</head>

<body>
    <div class="container">
        <h1>My First Bootstrap Page</h1>
        <p>This part is inside a .container class.</p>
        <p>The .container class provides a responsive fixed width container.</p>
        <p>Resize the browser window to see that its width (max-width) will change at different breakpoints.</p>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2"
        crossorigin="anonymous"></script>
</body>

</html>
Enter fullscreen mode Exit fullscreen mode

The output is shown below:

Image description

2) Fluid Container

Use the .container-fluid class to create a full width container, that will always span the entire width of the screen (width is always 100%):

Here is example of Fluid container:

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap demo</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>

<body>
    <div class="container-fluid">
        <h1>My First Bootstrap Page</h1>
        <p>This part is inside a .container-fluid class.</p>
        <p>The .container-fluid class provides a full width container, spanning the entire width of the viewport.</p>           
      </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2"
        crossorigin="anonymous"></script>
</body>

</html>
Enter fullscreen mode Exit fullscreen mode

The code output is shown below:

Image description

In next chapter we will discuss about Grid system.

Top comments (0)