CSS position takes a box out of (or offsets it within) normal flow. relative is the usual containing block for absolute children. fixed pins to the viewport (unless a transform ancestor creates a new containing block). sticky toggles between relative and fixed as you scroll.
This CSS cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.
Quick reference
- static: Default.
top/lefthave no effect. This is normal flow. - relative: Offset from where it would have been. Still occupies original space.
- absolute: Removed from flow. Positioned against the nearest positioned ancestor (or the initial containing block).
- fixed: Pinned to the viewport — unless a
transform,filter, orperspectiveancestor traps it. - sticky: Needs a
top(or other inset) and a scrolling ancestor. Overflow hidden on parents often kills it. - inset:
inset: 0istop/right/bottom/left: 0— fill the containing block. - z-index: Only applies to positioned boxes (and flex/grid items). Compare inside the same stacking context.
- Stacking:
opacity,transform, andfiltercreate new stacking contexts —z-index: 9999may still lose.
Copy-paste examples
Dropdown and sticky header
The menu is absolute against a relative parent. Sticky needs top and no overflow: hidden on wrappers.
.menu {
position: relative;
}
.menu-panel {
position: absolute;
top: 100%;
left: 0;
z-index: 10;
min-width: 12rem;
}
.site-header {
position: sticky;
top: 0;
z-index: 20;
background: white;
}Common mistakes
- Positioning every column instead of using Flexbox or Grid.
- Leaving
overflow: hiddenon a parent and wondering whystickynever sticks. z-index: 9999wars without a documented scale (10, 20, 30).- Using
fixedchat widgets that cover focusable controls and cookie banners.
FAQ
- Why did BLOGPH0 stop working? A parent with
transform,filter,perspective, orcontainbecomes the containing block. Inspect ancestors.
- Relative vs absolute for badges? Parent
relative, badgeabsolutewithtop/right. The parent still sizes from its in-flow content.
- Is sticky supported everywhere that matters? Yes in current evergreen browsers. Failures are almost always overflow or missing
top.
Related CSS cheat sheets
Build with this stack
When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.
Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.