SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

Welcome to CSS
The Box Model and SizingWriting Modes and Logical PropertiesSizing ElementsBorders and ShadowsDisplay and Document FlowNormal FlowFloats and ColumnsPositioning and StackingStacking and Z-Index Measuring boxes and predicting their positions
Box Model and Flow

Positioning and Stacking

Predict which reference box positions a label and whether its original space stays occupied.

A label can overlap the corner of a card while the paragraph below it stays in ordinary flow. To predict where each box lands, first ask whether positioning keeps its usual space. Then identify the box from which its offsets are measured.

Keep or release the space

With the initial position, static, a box stays in normal flow. position: relative lays it out there first, then allows an offset from that spot. Move a label down ten pixels this way and the next line stays where it was. The label can paint over it.

With position: absolute, the label leaves normal flow. Its siblings lay themselves out as though it occupied no space. To anchor the label to a card, give the card relative positioning. The card can stay in its original spot while its padding box becomes the label’s containing block, the reference for the label’s offsets. Offsets of zero at the top and right bring the label against the inside of the card’s border on those sides.

A dashed outline marks the relative badge’s original slot above the title. The absolute badge sits against the card’s top-right corner, and the title begins at the top left.

Follow the page as it scrolls

A fixed box also leaves normal flow. Its usual reference is the viewport, so it stays in view as the document scrolls. Some ancestor styles, including a transform, can establish a different reference.

A sticky heading keeps its place in flow. A top inset of zero lets it follow the top edge of its nearest scrollport as it would otherwise scroll out, until it reaches the boundary of its containing block. When positioned boxes overlap, their painting order is a separate decision.

Key Takeaways

  • Relative and sticky boxes keep space in flow. Absolute and fixed boxes release it.
  • Identify the containing block before predicting where a positioned box will appear.

Try it yourself

Try it yourself

Anchor a label to the card

HTML + CSS

Loading code editor…

Live preview

Updating…

Final output

No comparison yetChecks after 3s without edits
Loading your draft…

How is this lesson?

Previous lessonFloats and ColumnsNext lessonStacking and Z-Index
Edit on GitHubReport on GitHub
On this page
%

On this page

Keep or release the spaceFollow the page as it scrollsKey TakeawaysTry it yourself