×

css · level 2 · unit 5 · lesson 1

  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

nudges a box from its normal spot.

is how boxes are laid out unless you say otherwise: blocks stack, inline boxes sit in lines. Every element starts with position: static, which means it follows the flow.

position: relative lets you nudge a box with an : top, right, bottom or left. top: 10px pushes it 10px away from the top of where it was, so it moves down.

The space it left behind stays empty, and nothing else on the page moves. So a nudge can make boxes overlap.

<p>Fresh bread</p>
<p class="sticker">Half price!</p>
<p>Baked this morning</p>
.sticker {
  position: relative;
  top: -8px;
  left: 12px;
  padding: 8px;
  background-color: yellow;
}

Press show my page to see it here.

A negative offset moves the other way: top: -8px lifts the sticker up.