Relative
Relative positioning moves an element away from its own normal place, and keeps the space it would have used.
Apprentice · CSS · Updated
After this lesson you can
- Shift an element from its normal place with relative positioning and top or left, keeping its space in the page
Key takeaways
- Relative positioning moves an element away from the place it would normally be.
- A top of 30px moves it 30px down from its normal place, and a left of 30px moves it 30px right.
- The space it would have taken is kept, so nothing else moves, and it scrolls with the page.
relative position moves an element away from where it would normally be. top: 30px; left: 30px; shifts it 30px down and 30px right of its own normal place. The space it would have taken is still kept, so nothing else moves.
.div-2 {
position: relative;
left: 30px;
top: 30px;
}

As the page is scrolled, all elements scroll together.

Do it: nudge the Staff pick label
On your reading list, the Staff pick label next to Frankenstein should look like a sticker that's been stuck on a little low and to the right. The words around it must not move.
Here is the move:
| What | The value |
|---|---|
| Moved from | the label's own normal place |
| Down | 4px |
| Right | 6px |
| The words around it | stay where they are |
| The New label next to Dracula | stays as it is |
Your job: write one rule for the Staff pick label, class pick.
- Move it from its own normal place, keeping the space it would have taken, so nothing else moves.
- Move it
4pxdown and6pxright. - Don't change the New label, class
new.
Practiced live on the lesson page: write the CSS right there and check it.
Check yourself
2 questions to try on the lesson page.
So what
Relative is the gentle nudge: it moves one element a little without disturbing anything around it, and the next lesson uses it to mark a parent for absolute positioning.