Bootstrap 4 Tutorial
As you recall from the last chapter, in order for Bootstrap to surround the contents of a website, it needs a contained element.
Two container classes are provided, and containers are used to pad the material inside them:
To make a fixed-width, responsive container, use the .container class.
Keep in mind that depending on the screen size, its width (max-width) will vary:
| Extra small <576px | Small ≥576px | Medium ≥768px | Large ≥992px | Extra large ≥1200px | |
|---|---|---|---|---|---|
| max-width | 100% | 540px | 720px | 960px | 1140px |
Resize the browser window when you open the example below to observe how the container width varies at various breakpoints:
My First Bootstrap Page
This is some text.
To build a full width container that always spans the full width of the screen (width is always 100%), use the .container-fluid class:
My First Bootstrap Page
This is some text.
Containers are padded 15 pixels on the left and right by default, but not at the top or bottom. To make things seem even better, we therefore frequently employ spacing tools like additional padding and margins. .pt-3, for instance, indicates to “add a top padding of 16px”:
Alongside containers, other utilities like borders and colors are also frequently used:
To create responsive containers, you can also utilize the .container-sm|md|lg|xl classes.
The max-width of the container will vary depending on the viewport and screen size:
| Class | Extra small <576px | Small ≥576px | Medium ≥768px | Large ≥992px | Extra large ≥1200px |
|---|---|---|---|---|---|
.container-sm | 100% | 540px | 720px | 960px | 1140px |
.container-md | 100% | 100% | 720px | 960px | 1140px |
.container-lg | 100% | 100% | 100% | 960px | 1140px |
.container-xl | 100% | 100% | 100% | 100% | 1140px |
.container-sm
.container-md
.container-lg
.container-xl
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.