Bitpath

Boss lesson · Unit 03

Positioning

Lift boxes out of the flow and stack them in order

13 exercisesabout 3 min

What you practise

  • relative, absolute, fixed and sticky, the containing block, z-index and stacking contexts, a page shell built from all three tools

Try a question from this lesson

Pick one

The badge is drawn 10px lower than its normal place. What happens to "Milk" in the paragraph below?

HTML
<style>
  .badge { position: relative;
           top: 10px; }
</style>
<p>Tea <span class="badge">new</span></p>
<p>Milk</p>

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Five positions

relative offsets a box from its own place and keeps that place reserved.

absolute removes the box from the flow and places it against the nearest ancestor that is positioned (anything but static).

fixed places it against the viewport, so scrolling does not move it. sticky scrolls normally until it reaches its offset, then stays.

CSS
.a { position: static; }
.b { position: relative; }
.c { position: absolute; }
.d { position: fixed; }
.e { position: sticky; }

Concept

Stacking

Where boxes overlap, positioned ones are drawn above ordinary ones, and later ones above earlier ones.

z-index changes that order, but only on positioned boxes and on flex or grid items. On a static box it does nothing.

A positioned box with a z-index starts a stacking context: its children are layered inside it and cannot rise above what their parent beats.

10 more exercises in the app

  • 2× type the answer
  • 5× multiple choice
  • 1× true or false
  • 1× fill the blanks
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy