In Bootstrap 5, containers are fundamental building blocks used to structure and layout content. They provide responsive fixed-width or fluid-width containers that help maintain proper alignment and spacing.
Types of Containers in Bootstrap 5
Bootstrap 5 provides three types of containers:
1. Default (Fixed-width) Container
This container is responsive and has a fixed width at each breakpoint.
<div class="container">
<!-- Your content here -->
</div>
- The width of
.container
changes based on the screen size:- 576px (sm) → 540px wide
- 768px (md) → 720px wide
- 992px (lg) → 960px wide
- 1200px (xl) → 1140px wide
- 1400px (xxl) → 1320px wide
2. Fluid Container (100% Width)
This container always takes up the full width of the viewport.
<div class="container-fluid">
<!-- Your content here -->
</div>
- It stretches across the entire screen width regardless of the screen size.
3. Responsive Containers (container-{breakpoint}
)
These containers are fluid up to a specific breakpoint, then become fixed-width.
<div class="container-md">
<!-- Your content here -->
</div>
- Examples of
container-{breakpoint}
classes:container-sm
→ Full width until576px
, then fixedcontainer-md
→ Full width until768px
, then fixedcontainer-lg
→ Full width until992px
, then fixedcontainer-xl
→ Full width until1200px
, then fixedcontainer-xxl
→ Full width until1400px
, then fixed
Choosing the Right Container
- Use
.container
when you want a responsive fixed-width layout. - Use
.container-fluid
when you need a full-width layout. - Use
.container-{breakpoint}
when you want a fluid layout that becomes fixed at a certain screen size.
Would you like an example using Bootstrap grid within a container?
0 comments:
Post a Comment