Positioning
Change a control, or edit the CSS. The preview uses that same CSS.
Numeric changes ease so you can watch them.
The offset sliders did nothing while position was static, then the same top and left values moved the note once you chose relative, absolute, fixed, or sticky. The second layer stayed put so you could see which one paints on top.
+Go deeper
Static is the flow
static is the initial value. The box stays in normal flow, where display from the last lesson still decides the line. Top, left, right, bottom, and z-index do not apply. The sliders are off for that reason.
Relative offsets without leaving
relative keeps the box in flow and then offsets it from that spot. The gap it left behind stays. With a set left, a right offset is ignored in left-to-right text. Top wins over bottom the same way. The code can contain all four, and the used values follow that rule.
Absolute uses a positioned ancestor
position: absolute removes the box from flow. It is placed against the nearest ancestor whose position is not static. If there is none, the initial containing block is used. The in-flow siblings close up, because the absolute box no longer takes a line.
| Value | In flow? | Offset origin |
|---|---|---|
| static | Yes | Offsets do not apply |
| relative | Yes, then shifted | Its own place in the flow |
| absolute | No | Nearest positioned ancestor |
| fixed | No | The viewport |
| sticky | Yes, until it sticks | The scrollport, inside its parent |
Fixed and sticky
position: fixed is taken against the viewport. In this preview that viewport is the frame, so the note stays while you scroll the band. On a full page it stays against the browser window. position: sticky scrolls with the content and then sticks, and it lets go when its parent ends. That is why the band is taller than the frame.
The second layer
z-index applies to a positioned box. The gray layer is absolute with z-index 1. Lower the note below that and the gray layer paints on top. Static ignores z-index, which is why that slider is off until you leave static.
Guided challenge
Positioning
The style attribute says position relative. The script logs static. Read the first declaration instead of printing a fixed word.
Your console output appears here.
EXPECTED CONSOLE OUTPUT
relative 16px 20px Note
Hints 0/2
Use all hints or make 3 failed runs (0/3).
Free sandbox
Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.
Your console output appears here.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 150 XP. You can always revisit it.