Lesson 3 of 8

Positioning

Goal

One element on top of another

01

Explanation

position: absolute takes an element out of the normal flow of the page and positions it relative to its nearest positioned ancestor, meaning the closest element containing it whose position isn't static.

The whole trick is to put position: relative on the parent so it becomes the reference point, then put absolute on the child. Forget relative on the parent and the child ends up in the corner of the page.

Use inset-block-start and inset-inline-start instead of top and left. The logical properties follow the direction of the page and flip with it, while top and left stay the same whatever the direction.

02

Your task

Place .badge at the top of .card on its start edge, and make it appear above everything around it.

Checks

5 checks
  1. The card becomes the reference point with relative
  2. The badge leaves the normal flow with absolute
  3. The badge is at the top of the card, not the middle
  4. The badge is on the start edge
  5. The badge has a z-index so it doesn't hide under other elements
03

Hints

0/3
Track lessons0 of 8 done

Go deeper into the box model, custom properties, positioning, container queries and more, so you understand what's really going on behind the styles you see.

Intermediate level, 8 lessons, 1.5 hours in total.

index.html
Preview
index.html100%
–/5

Press “Run and check” to grade your code.

5 checks listed under “Your task”.

Track lessons0 of 8 done

Go deeper into the box model, custom properties, positioning, container queries and more, so you understand what's really going on behind the styles you see.

Intermediate level, 8 lessons, 1.5 hours in total.