×

css · level 2 · unit 5 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

pins a box to the screen itself.

position: fixed places a box against the viewport, not the page. Scroll as far as you like and a fixed help button stays in its corner.

Like absolute, it leaves the normal flow. Unlike absolute, a positioned parent does not hold it: it measures from the edges of the screen.

When boxes overlap, picks who is in front. It is a plain number, and higher numbers sit closer to you. It needs a positioned box: on a plain static block, it does nothing.

<p class="long">A very long page about hedgehogs.</p>
<button class="help">Help</button>
.help {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  padding: 12px 20px;
  border-radius: 24px;
  color: white;
  background-color: teal;
}
.long {
  height: 900px;
}

Press show my page to see it here.

Scroll inside the preview: the Help button never moves.