Pick only the links inside the nav, so the menu can look different from the links in the text.
Every site menu looks different from the links in its articles, and one short selector is how it is done.
A page has links in two places: in the menu at the top, and in the sentences below. A rule on a styles both. To change only the menu, the rule has to say where the links are.
Make your prediction first. Help opens once you've locked it in.
<style>
header {
background-color: navy;
color: white;
}
</style>
<header>
<h1>Owls club</h1>
<nav>
<ul>
<li><a href="https://example.com/home">Home</a></li>
<li><a href="https://example.com/results">Results</a></li>
</ul>
</nav>
</header>
<p>Read the <a href="https://example.com/results">results</a> from last week.</p>
Read the code. The header rule sets a navy background and white text. The menu is a list of links inside a <nav> inside the header. What colour are the menu links?
Compare the page with your prediction. Then add this rule under the header rule, and watch the menu links change while the link in the paragraph stays blue.
nav a {
color: white;
}
| Code | What it does | Why |
|---|---|---|
header { color: white; } |
Makes the header's own words white | The links inside keep their blue. A link has its own colour, so a rule has to name the link |
nav a { color: white; } |
Makes the links in the nav white | The space means inside: nav a picks every a that sits within a nav |
| the link in the paragraph | Stays blue | It is an a, but it is not inside a nav, so the rule does not pick it |
nav a:hover { text-decoration: underline; } |
Underlines a menu link while the pointer is over it | :hover means "while the pointer is over it". Copy this for now; the colon is part of the selector |
<style>
header {
background-color: navy;
color: white;
}
</style>
<header>
<h1>Owls club</h1>
<nav>
<ul>
<li><a href="https://example.com/home">Home</a></li>
<li><a href="https://example.com/results">Results</a></li>
</ul>
</nav>
</header>
<p>Read the <a href="https://example.com/results">results</a> from last week.</p>
<style>
nav a {
color: crimson;
}
</style>
<nav>
<a href="https://example.com/home">Home</a>
<a href="https://example.com/results">Results</a>
</nav>
<p>Read the <a href="https://example.com/rules">rules</a>.</p>
<footer>
<a href="https://example.com/contact">Contact</a>
</footer>
Look at the rule, then at each link.
A space, a comma or a different order?
Sam's rule is on the nav.
Fill in the colour of each link. The browser's usual link colour is blue.
| link | colour |
|---|---|
| Home, in the nav | |
| Results, in the nav | |
| rules, in the paragraph | |
| Contact, in the footer |
Sam wants white menu links on the navy header. The links are still blue, and there is no error. Click the line that causes it.
The link in the paragraph keeps its underline.
Add a line inside the nav a rule.
text-decoration: none; removes the underline.

Pick only the links inside the <footer>.
Use the same shape for the footer: write the part first, then a space, then the tag.
footer a { color: gray; }

Remove the underline from the menu links only.
This ticks when your page has all of the above.
Make the links in the footer gray.
This ticks when your page has all of the above.
Style this club page: a dark header, light menu links that fit it, and the link in the text left as it is.
Start with the header: one rule for the navy background and white text.
Then a rule for the menu links only. The link in the paragraph must not change.
Add text-decoration: none; to the menu links, or list-style: none; on the ul if you want no bullets.

Give the page a dark header and light menu links, and leave the link in the text alone.
This ticks when your page has all of the above.
Students pick only the links inside a nav with a descendant selector, and find out that a colour on the nav does not reach the links, and that a space means inside. About 40 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
Read the unit primer "Layout and components" first, then do the Make task yourself in the playground (about 5 minutes).
A descendant selector is two selectors with a space between: nav a picks every a anywhere inside a nav. A link keeps its own colour until a rule names it, which is why nav { color: white; } leaves the menu blue. :hover is shown as a line to copy for now, not taught: it means "while the pointer is over it".
Reading nav a as both. Ask which of the two words names the element that changes, and what the first word does.
Stretch: Use nav a:hover with a background-color to make a link light up when the pointer is over it. Copy the line from the Run table and change it.
Support: Give students the Modify starter and do the first task together on the board: the part first, then a space, then the tag.
Next lesson looks at why some elements start a new line and others sit in a line, which a menu needs to run across the page. Class idea: find three menus on websites you use and say what colour their links are.