CSS · CSS Tutorial · Lesson 22
CSS Position
static, relative, fixed, absolute and sticky.
The position property specifies the positioning method. Elements are then placed with top, bottom, left and right.
| Value | Behaviour |
|---|---|
| static | Default — normal flow, top/left are ignored |
| relative | Offset from its normal position |
| absolute | Positioned relative to the nearest positioned ancestor |
| fixed | Relative to the viewport; stays when scrolling |
| sticky | Toggles between relative and fixed while scrolling |
Example
<style>
.parent { position: relative; height: 150px; border: 3px solid #73AD21; }
.child { position: absolute; bottom: 10px; right: 10px; background: tomato; color: white; padding: 8px; }
.rel { position: relative; left: 30px; background: lightblue; }
</style>
<div class="rel">relative: moved 30px right</div>
<div class="parent">
position: relative parent
<div class="child">absolute: bottom right</div>
</div>
Keep reading “CSS Position”
Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.