Bootstrap Position & Layout Patterns

Fixed Position

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 Header

Use .fixed-top to keep an element at the top of the viewport.

Fixed Header - Always visible at top
Page content area (would scroll behind header)

Fixed Bottom Footer

Use .fixed-bottom to keep an element at the bottom of the viewport.

Page content area (would scroll above footer)
Fixed Footer - Always visible at bottom

Production Code Example

<!-- 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 Position

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.

Basic Sticky Navigation

Use .sticky-top to make an element stick to the top when scrolling past it.

Scroll down to see sticky behavior...

Content continues below the sticky nav...

Keep scrolling to see the nav stay fixed at top.

Responsive Sticky Breakpoints

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

Sticky Bottom

Use .sticky-bottom to stick elements to the bottom of their container.

Scroll down to see sticky bottom behavior...

Sticky Bottom Element

Sticky Sidebar Pattern

Common pattern: sticky sidebar that remains visible while main content scrolls. Add custom top offset with inline style or utility class.

Main Content

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...

Sticky Sidebar

Stays visible while scrolling main content.

Clearfix

Use .clearfix to clear floated content within a container. This ensures the parent container wraps around floated children properly.

With Clearfix (Correct)

The container properly expands to contain the floated buttons.

This paragraph correctly appears below the container.

Without Clearfix (Broken Layout)

Without clearfix, the container collapses and subsequent content wraps around floats.

Without clearfix, this text wraps around the floats incorrectly!

Image Float Pattern

Classic pattern: float an image with text wrapping around it.

Floated placeholder image

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.

Text Truncation

Use .text-truncate to truncate long text with an ellipsis. Requires display: block or display: inline-block and a defined width.

Block Level Truncation

Block elements truncate when they have a constrained width.

This is a very long text that will be truncated with an ellipsis when it exceeds the container width.

Inline Truncation

Inline elements require .d-inline-block for truncation to work.

Status: This is a very long inline status message

Table Cell Truncation

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.

Card with Truncated Content

Very Long Card Title That Gets Truncated When Too Wide

This card description is also truncated with an ellipsis for consistent card heights.

Read More

Vertical Rule

Use .vr to create vertical dividers. Works best in flex containers where it automatically inherits the container height.

Basic Vertical Rule

In a flex container, .vr automatically stretches to match sibling height.

Left
Right

Vertical Divider Between Items

Item 1
Item 2
Item 3

Button Toolbar with Vertical Rule

Use vertical rules to separate button groups within a toolbar.

Navigation with Vertical Dividers

Styled Vertical Rule

Customize with background color and opacity utilities.

Default
Primary
Success (50% opacity)
Danger
End

Color & Background Helpers

Use .text-bg-{color} to set both background and contrasting text color automatically. This ensures proper color contrast for accessibility.

All Color Variants

.text-bg-primary - White text on primary blue background
.text-bg-secondary - White text on secondary gray background
.text-bg-success - White text on success green background
.text-bg-danger - White text on danger red background
.text-bg-warning - Dark text on warning yellow background
.text-bg-info - Dark text on info cyan background
.text-bg-light - Dark text on light gray background
.text-bg-dark - White text on dark background

Badges with Color Helpers

Apply to badges for consistent, accessible color combinations.

Primary Secondary Success Danger Warning Info Light Dark

Custom Alert Pattern

Create alert-like components with guaranteed color contrast.

Warning! This custom alert ensures proper text contrast automatically.
Error! Critical message with accessible color combination.
Success! Operation completed successfully.

Card Headers with Color Helpers

Primary Header
Card content here.
Success Header
Card content here.
Dark Header
Card content here.