Position utilities
Position utilities place elements relative, absolute, fixed or sticky and pin them to edges.
In this page:
Syntax
<div class="position-relative">
<div class="position-absolute top-0 end-0">corner</div>
</div>
Position utilities
Use .position-static, -relative, -absolute, -fixed and -sticky. Then edge helpers .top-0, .start-0, .end-0, .bottom-0 and .translate-middle position the element, and .fixed-top, .fixed-bottom and .sticky-top provide common shortcuts.
Absolute children need a relative parent.
Note:
An absolute element positions relative to its nearest positioned ancestor.
Example: Position utilities
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
<div class="position-relative bg-light border" style="height: 8rem">
<span class="position-absolute top-0 start-0 badge text-bg-primary">top-start</span>
<span class="position-absolute top-50 start-50 translate-middle badge text-bg-success">centre</span>
<span class="position-absolute bottom-0 end-0 badge text-bg-danger">bottom-end</span>
</div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
- Forgetting a position-relative parent
- Using fixed on many elements
- Covering content with fixed bars
Chapter Summary
- position-relative, absolute, fixed, sticky
- top-0, start-0, end-0, bottom-0
- translate-middle centres on the edge
- Absolute needs a relative parent
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: