Chapter practice task
Task: Build a sticky header with a badge on your logo
- Make your header stick to the top while the page scrolls with
position: sticky. - Turn your navigation links into inline-block “pills” with padding.
- Add a small “Available” badge to the corner of your logo with
position: absolute. - Add a “Back to top” button fixed to the bottom-right corner.
- Test on a phone-sized screen and make sure nothing covers your content.
By the end of this chapter
- You know the difference between block, inline and inline-block elements
- You can hide elements correctly with
display: none - You can use relative, absolute, fixed and sticky positioning without breaking your layout
Quick answers for this chapter
Why won’t my span accept a width?
Spans are inline elements. Change them to display: inline-block or block.
Should I build layouts with position absolute?
No. Use Flexbox and Grid for layouts; use positioning for small overlays like badges and tooltips.
What does z-index do?
It decides which positioned element appears on top when they overlap.