Python CSS Positioning (relative, absolute, fixed, sticky)
The position property breaks elements out of normal document flow to place them at exact coordinates (top, right, bottom, left). Master the 4 key modes: relative, absolute, fixed, and sticky.
"position: relative is marking your current seat with a bookmark. position: absolute is stepping out of the line to stand in the top-right corner of the room. position: fixed is strapping a helmet to your eyes so it stays in your vision as you walk. position: sticky is scrolling until you hit the ceiling, then sticking like a magnet."
Deep Dive: How It Works
position: relative: Element stays in normal flow, but unlocks coordinate offsets (top, left) AND serves as an anchor parent for absolute children.
position: absolute: Breaks completely out of page flow. Positions itself relative to the nearest parent with position: relative (or the whole page if none exists).
position: fixed: Locks itself relative to the browser viewport window. Stays frozen in place as the user scrolls (e.g. chat bubble widget).
position: sticky: The modern hybrid! Scrolls naturally like a normal element until it reaches a threshold (e.g. top: 0;), then sticks to the top of the screen!
Syntax Blueprint
/* Parent Anchor */
.card {
position: relative;
}
/* Absolute Badge in Top Right Corner */
.badge {
position: absolute;
top: 8px;
right: 8px;
}
/* Sticky Header */
.header {
position: sticky;
top: 0;
z-index: 50;
}Relative parent anchors absolute child; sticky pins headers during scroll.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using position: absolute without a relative parentWhy it happens: The absolute element flies to the top-right of the entire browser window instead of the card!
How to fix: Always add position: relative; to the parent card container.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Create an absolute corner badge
Write a CSS rule for .corner-badge with position: absolute; top: 0; and right: 0;
Finished reading and practicing?
Mark this lesson as completed to update your course progress.