Sikau

CSS · Day 11 · about 25 min

Positioning

relative, absolute, fixed and sticky.

Out of the flow

A "New" badge on a card's corner, a header that stays on screen while you scroll, a chat button floating in the corner — these break out of normal flow with the position property.

Position values

  • relative — stays in flow; becomes the anchor for absolute children.
  • absolute — removed from flow, placed with top/right/bottom/left inside the nearest positioned ancestor.
  • fixed — pinned to the screen (stays put when scrolling).
  • sticky — scrolls normally until it reaches a threshold (e.g. top: 0), then sticks.
  • z-index decides what's on top when positioned things overlap.

The rest of this lesson

  • The containing blockexplain
  • Sticky, fixed and stackingexplain
  • Where's the badge?predict
  • Pick the positionmatch
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 19 lessons of CSS