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 | XXL ≥1400px | |
---|---|---|---|---|---|---|
max-width | 100% | 540px | 720px | 960px | 1140px | 1320px |
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.
While the largest breakpoint in Bootstrap 4 is Extra large (≥1200px), the XXL breakpoint (≥1400px) is new in Bootstrap 5.
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 come with left and right padding by default, but no top or bottom padding. Therefore, we often use spacing utilities, such as extra padding and margins to make them look even better. For instance, “add a large top padding” is what .pt-5 signifies:
Alongside containers, other utilities like borders and colors are also frequently used:
In a later chapter, you will discover much more about colors and border utilities.
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 | XXL ≥1400px |
---|---|---|---|---|---|---|
.container-sm | 100% | 540px | 720px | 960px | 1140px | 1320px |
.container-md | 100% | 100% | 720px | 960px | 1140px | 1320px |
.container-lg | 100% | 100% | 100% | 960px | 1140px | 1320px |
.container-xl | 100% | 100% | 100% | 100% | 1140px | 1320px |
.container-xxl | 100% | 100% | 100% | 100% | 100% | 1320px |
.container-sm
.container-md
.container-lg
.container-xl
.container-xxl
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.