1. Normal flow
By default, elements are position: static. Offsets like top and left do not apply.
This single file demonstrates relative, absolute, fixed, and sticky.
Some examples intentionally show how positioning changes when the containing block changes.
By default, elements are position: static. Offsets like top and left do not apply.
A relative element stays in flow, but can be visually shifted. It also establishes a containing block for absolute children.
child: relative; top/left applied
child: absolute; bottom/right
The absolute child anchors to this parent because the parent is position: relative.
If no ancestor is positioned, an absolute element uses the initial containing block instead of the local card.
The orange note escapes this card area because it is positioned against the page, not this local demo box.
absolute with no local positioned parent
A fixed element ignores the relative parent for placement. It still pins itself to the viewport.
Even though this wrapper is relative, the blue note is fixed to the screen, not to this box.
inside relative in DOM, but fixed to viewport
This is useful for overlays, floating actions, and persistent UI.
This block sticks to the top of its scroll container until its parent section scrolls away.
I am position: sticky with top: 56px.
Scroll inside this list. Each section header is sticky. When the next section reaches the top, the previous sticky header gets pushed upward.
Active sticky section: A
B — Relative concepts
Relative elements remain in normal flow.
Offset properties move the rendered box visually.
The original layout space is still reserved.
Relative is commonly used just to establish an anchor for absolute children.
It is one of the safest positioning tools for local layout control.
C — Fixed concepts
Fixed elements attach to the viewport.
They are removed from normal flow like absolute elements.
They are often used for nav bars, floating buttons, drawers, and global notices.
On mobile, be careful with browser UI bars that can change visible viewport height.
Transforms and special containing contexts can affect behavior in advanced cases.