Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Choose a CSS positioning value by asking three questions: does the element keep its space in normal layout, what determines its offsets, and how does it behave while scrolling? relative keeps its place in the flow; absolute and fixed do not; sticky keeps its place and can become offset while scrolling. The details of the containing block and scroll ancestors determine where each one goes.
Start with normal flow
Before positioning, an element’s default is position: static. It takes part in normal document layout, and inset properties such as top and left do not reposition it. Normal flow determines where the element sits and how neighboring content lays out around it.
The four positioning values below change that baseline in different ways. An element can be visually displaced without its original space moving, or removed from the flow altogether. Its offsets also need a reference: that may be its original position, a containing block, a scrolling ancestor, or usually the viewport.
Compare the four positioning values
| Value | Keeps normal-flow space? | Typical positioning reference | Teaching example |
|---|---|---|---|
relative |
Yes | Its normal position for offsets; can establish a local containing block | Nudge a label or anchor an overlay within a component |
absolute |
No | Nearest applicable containing block | Badge, icon, or overlay inside a card with a positioned parent |
fixed |
No | Usually the viewport in visual media; ancestor properties can change the containing block | Persistent help button or viewport-level control |
sticky |
Yes | Nearest scrolling ancestor and containing block | Section heading or table header that sticks during a scroll interval |
These are patterns for understanding layout, not rules that every design should follow. The right choice depends on flow participation, positioning reference, and scrolling behavior together.
Recommended Free Tools
When should you use position: relative?
Use relative when an element should retain its original place in layout but appear offset from that position. For example, a label can be nudged slightly without causing the content after it to move into the vacated space. The element’s original flow space remains reserved; its painted position moves.
#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
relative is also commonly used to make an element the local containing block for an absolutely positioned descendant. That gives a component such as a card a deliberate reference for an internal badge or icon, rather than leaving that descendant to be positioned against a more distant ancestor.
When should you use position: absolute?
Use absolute for an element that should not take up its usual space in normal flow and whose offsets should be measured against a containing block. A common teaching example is a badge positioned inside a card: make the card a positioned parent, then place the badge within that card’s bounds.
Rank #2
An absolutely positioned element uses the nearest applicable containing block, commonly the nearest ancestor whose position is not static. If no applicable ancestor establishes one, its offsets are resolved against the initial containing block. If an overlay appears in an unexpected location, inspect its ancestors to find the reference it is actually using.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →When should you use position: fixed?
Use fixed when an element should be removed from normal flow and typically stay in a viewport-relative position as the page scrolls, such as a persistent help control. In visual media, the viewport is the usual reference, but it is not guaranteed: an ancestor with a non-none transform, perspective, or filter can establish a different containing block.
Rank #3
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
If fixed content moves with a region or seems attached to a component, inspect those ancestor properties before changing its offsets. “Fixed” does not unconditionally mean “fixed to the viewport.”
How does position: sticky work?
sticky keeps its normal-flow space. As scrolling reaches the relevant inset threshold, the element is offset relative to its nearest scrolling ancestor, while remaining constrained by its containing block. It therefore sticks only over the portion of scrolling allowed by that containing block; it is not simply fixed to the viewport for the whole page.
Set a non-auto inset on the axis where the element should stick. For example, a top-sticking heading needs a non-auto top inset. MDN notes that “At least one inset property (top, inset-block-start, right, inset-inline-end, etc.) needs to be set to a non-auto value for the axis on which the element needs to be made sticky.”
For a useful mental model, imagine a heading inside a bounded section on a tall scrolling page. The heading can stick as the page scrolls through that section, but the section’s bounds limit how long it can remain offset. An ancestor with overflow: hidden, auto, scroll, or overlay may determine the sticky scrolling mechanism—even if a different ancestor is the one visibly scrolling.
Why is my positioned element in the wrong place or behind something?
- An absolute element is misplaced: Find its nearest applicable containing block by inspecting ancestors. If the design calls for positioning inside a component, establish an intentional local context there.
- A fixed element scrolls with a region: Check ancestors for a non-
nonetransform, perspective, or filter that may change its containing block. - A sticky element never sticks: Check for a non-
autoinset on the intended axis, then inspect ancestors withoverflow: hidden,auto,scroll, oroverlay. Also check whether its containing block provides enough room for a sticky interval. - An element overlaps content unexpectedly: Check stacking contexts before increasing
z-index. Fixed and sticky elements always create stacking contexts; relative and absolute elements create one whenz-indexis notauto. A child’s highz-indexis interpreted inside its own stacking context, so it cannot necessarily rise above content in another context.
Choose by behavior, not by a slogan
- Choose
relativeto preserve flow space while offsetting an element, or to give an absolute descendant a local reference. - Choose
absolutewhen the element should not reserve normal-flow space and should be positioned against a containing block. - Choose
fixedwhen the element should leave normal flow and usually remain viewport-relative during scrolling, after checking ancestor effects. - Choose
stickywhen the element should remain in flow but become offset during a bounded scrolling interval.
For further CSS study, the publisher page for CSS in Depth, Second Edition describes a broader CSS reference. Manning’s CSS in Depth catalog entry lists positioning and stacking contexts among its topics.
Quick Recap
Best Value
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




