Boss lesson · Unit 04
A component
Build a card and a nav bar, then debug a broken layout
What you practise
- A card and a navigation bar, responsive and accessible, then a broken layout debugged from its CSS
Try a question from this lesson
Pick one
This product card has no CSS yet. How does the browser lay it out?
<article class="card">
<img src="tea.jpg" alt="Green tea">
<h3>Green tea</h3>
<p>Loose leaf, 100g</p>
<a href="/tea">Buy</a>
</article>Correct answer
Stacked top to bottom, in source order
Why
HTML alone already gives a usable layout: the heading and paragraph are blocks, so each piece lands under the one before. Good structure first means the card still works if the stylesheet fails to load.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
A navigation bar
A navigation bar is a <nav> holding a list of links, so a screen reader can announce it and say how many links there are. Flexbox turns the list into a row.
aria-current="page" marks the link for the page you are on. A screen reader reads it out, and CSS can select it with [aria-current="page"].
<nav>
<ul>
<li>
<a href="/" aria-current="page">
Home</a>
</li>
<li><a href="/shop">Shop</a></li>
</ul>
</nav>Concept
Debugging a layout
When a layout is broken, do what the browser does.
Find the one box that is the wrong size or in the wrong place. Ask which layout its parent runs: block, flex or grid. Check which rule actually won for each property. Then add up the numbers: content, padding, border and gaps.
The browser's developer tools show all four for any element you click.
10 more exercises in the app
- 4× type the answer
- 4× multiple choice
- 1× fill the blanks
- 1× true or false
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.