.fixed-top and .fixed-bottom
position elements relative to the viewport and require body padding to prevent content overlap.
Fixed elements are removed from normal document flow and positioned relative to the viewport. They remain visible at their position regardless of scrolling.
.fixed-top or .fixed-bottom,
add padding to your <body> to prevent content from being hidden behind
the fixed element. Example: body { padding-top: 60px; padding-bottom: 60px; }
Use .fixed-top to keep an element at the top of the viewport.
Use .fixed-bottom to keep an element at the bottom of the viewport.
<!-- Add to your stylesheet or <style> tag -->
<style>
body {
padding-top: 60px; /* Height of fixed header */
padding-bottom: 60px; /* Height of fixed footer */
}
</style>
<!-- Fixed header -->
<header class="fixed-top bg-dark text-white p-3">
Fixed Header
</header>
<!-- Fixed footer -->
<footer class="fixed-bottom bg-dark text-white p-3">
Fixed Footer
</footer>
Sticky elements toggle between relative and fixed positioning. They scroll with content until reaching a threshold, then "stick" in place. Unlike fixed, they remain in document flow.
Use .sticky-top to make an element stick to the top when scrolling past it.
Content continues below the sticky nav...
Keep scrolling to see the nav stay fixed at top.
Apply sticky behavior only at certain breakpoints using .sticky-{breakpoint}-top.
.sticky-sm-top - Sticky on sm (576px) and up.sticky-md-top - Sticky on md (768px) and up.sticky-lg-top - Sticky on lg (992px) and up.sticky-xl-top - Sticky on xl (1200px) and up.sticky-xxl-top - Sticky on xxl (1400px) and up
Use .sticky-bottom to stick elements to the bottom of their container.
Scroll down to see sticky bottom behavior...
Common pattern: sticky sidebar that remains visible while main content scrolls.
Add custom top offset with inline style or utility class.
This content scrolls normally. The sidebar stays visible as you scroll.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
More content to enable scrolling...
Even more content here...
Stays visible while scrolling main content.
Use .clearfix to clear floated content within a container.
This ensures the parent container wraps around floated children properly.
The container properly expands to contain the floated buttons.
This paragraph correctly appears below the container.
Without clearfix, the container collapses and subsequent content wraps around floats.
Without clearfix, this text wraps around the floats incorrectly!
Classic pattern: float an image with text wrapping around it.
Text wraps around the floated image. The clearfix ensures the container properly encompasses both the floated image and the text content. This is a common pattern for article layouts with inline images.
Use .text-truncate to truncate long text with an ellipsis.
Requires display: block or display: inline-block and a defined width.
Block elements truncate when they have a constrained width.
Inline elements require .d-inline-block for truncation to work.
Status: This is a very long inline status message
For table cells, use table-layout: fixed and define column widths.
| Name | Description |
|---|---|
| Product Alpha | This is a very long product description that demonstrates text truncation within a table cell. It will be cut off with an ellipsis. |
| Another Product with Long Name | Short description. |
This card description is also truncated with an ellipsis for consistent card heights.
Read More
Use .vr to create vertical dividers. Works best in flex containers
where it automatically inherits the container height.
In a flex container, .vr automatically stretches to match sibling height.
Use vertical rules to separate button groups within a toolbar.
Customize with background color and opacity utilities.
Use .text-bg-{color} to set both background and contrasting text color
automatically. This ensures proper color contrast for accessibility.
Apply to badges for consistent, accessible color combinations.
Create alert-like components with guaranteed color contrast.