Lesson 6 of 8

Sticky header

Goal

A header that stays put while the list scrolls under it

01

Explanation

In a long list, the heading disappears with the first scroll and the user forgets where they are. position: sticky keeps an element in its normal place until it reaches a threshold you set, then it sticks there for as long as its parent is in view.

That threshold is required: sticky without inset-block-start (or top) does nothing. The element sticks to its nearest ancestor that can scroll, which is why the container needs a limited height and overflow-y: auto.

Be careful: putting overflow: hidden on any element between the header and the container you have in mind makes that element the reference instead, and since it doesn't scroll, nothing sticks. Give the header a background too, or the rows will show through it.

02

Your task

Make .panel scroll its content inside itself, pin .bar to the top of the panel with position: sticky and inset-block-start: 0, and give the bar a background that hides whatever scrolls under it.

Checks

5 checks
  1. The container scrolls its content inside itself
  2. The header is sticky
  3. The header sticks exactly at the top of the container
  4. The header stays visible at the top of the container after scrolling
  5. The header has a background that hides what scrolls under it
03

Hints

0/3
Track lessons0 of 8 done

Learn page layout, form validation, motion and accessibility: the things that make an interface comfortable to use in real life, not just nice to look at.

Advanced level, 8 lessons, 2 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

Learn page layout, form validation, motion and accessibility: the things that make an interface comfortable to use in real life, not just nice to look at.

Advanced level, 8 lessons, 2 hours in total.