Careeroza
position
Position Values
| Value | Positioned relative to | In the normal flow? |
|---|---|---|
static (default) | not positioned | yes |
relative | its own normal position | yes (space kept) |
absolute | nearest positioned ancestor | no |
fixed | the viewport (stays when scrolling) | no |
sticky | normal until a scroll threshold, then sticks | yes |
Positioned elements are moved with top, right, bottom and left.
relative + absolute
Example
The classic pattern: a relative parent and an absolute child, such as a badge on a card:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
.card { position: relative; width: 220px; padding: 20px; border: 1px solid #ccc; font-family: Arial; }
.badge { position: absolute; top: -10px; right: -10px; background: tomato; color: white;
border-radius: 50%; width: 28px; height: 28px; display: grid; place-items: center; }
</style>
</head>
<body>
<div class="card">Notifications <span class="badge">3</span></div>
</body>
</html>Result
sticky
Example
Scroll inside the preview: the header sticks to the top:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body { font-family: Arial; margin: 0; }
header { position: sticky; top: 0; background: #282A35; color: white; padding: 10px; }
p { padding: 0 10px; }
</style>
</head>
<body>
<header>Sticky header</header>
<p>Scroll down...</p><p>.</p><p>.</p><p>.</p><p>.</p><p>.</p><p>.</p><p>.</p><p>The end.</p>
</body>
</html>Result