Skip to content
engineering workbench.by StudyPort Academy
Learning path
Intermediate18 minLESSON 10 / 16

Positioning

Change a control, or edit the CSS. The preview uses that same CSS.

position

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.

Where each position value measures from
ValueIn flow?Offset origin
staticYesOffsets do not apply
relativeYes, then shiftedIts own place in the flow
absoluteNoNearest positioned ancestor
fixedNoThe viewport
stickyYes, until it sticksThe 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.

04

Guided challenge

Positioning

The style attribute says position relative. The script logs static. Read the first declaration instead of printing a fixed word.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

EXPECTED CONSOLE OUTPUT

relative
16px
20px
Note

Hints 0/2

    Use all hints or make 3 failed runs (0/3).

    05

    Free sandbox

    Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.

    Opening editor…
    LIVE PREVIEW
    Console 0

    Your console output appears here.

    Saved on this deviceJavaScript · ES2022
    06

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01When do top and left apply?
    02What is the containing block for an absolute box?

    Ready to call this one understood?

    Mark this lesson complete to earn 150 XP. You can always revisit it.

    Sign in to save progress
    Next lesson