Students mark chosen elements with a class and style only those with a dot rule, and find out that the names must match and the dot stays in the CSS.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 10 min · Investigate 8 min · Modify 8 min · Mix it up 4 min · Make 10 min
Read the unit primer "Lists, links and pictures in 5 minutes" first, then do the Make task yourself in the playground (about 5 minutes).
A class is a name you choose and put on elements with class="name". In the CSS a rule starting with a dot, .name { }, styles every element with that class. The dot is only in the CSS. Students already know that p { } styles all paragraphs; the new idea is choosing which ones.
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
With your partner, point to each paragraph and say whether it turns crimson. Hold up 1, 2, 3 or 4 fingers for the option you chose.
Take a vote before running. Ask someone who chose all four what the class is for. The idea to land: the class is the mark, the rule picks by the mark.
Swap pages with a partner. Without running them, read each tag with a class and say which rule it matches.
Listen for students who match by eye and miss a capital letter. Ask what the browser does when the names differ.
Believing the dot belongs in both places. Ask where each of the two names is written, and which one is the CSS.
| What you will see | A question to ask | The fix |
|---|---|---|
| The rule does nothing and there is no error. | Are the class name in the tag and the name after the dot spelt exactly the same? | Make the two names identical, capitals included, and put the dot only in the CSS. |
| Every paragraph changes colour. | Is the rule's selector p or .winner? | Change the selector to a dot and the class name, and put the class on only the elements you want. |
| The class is written as class=".winner". | Where does the dot go? | The dot is only in the CSS. In the tag write class="winner". |
One possible solution for each task. Other correct programs are fine.
<style>
.note {
color: crimson;
}
</style>
<h1>Sports day</h1>
<p>Sports day is on Friday.</p>
<p class="note">Bring a hat.</p>
<p class="note">Bring water.</p>
<p class="note">Races start at 9 am.</p>
<style>
.note {
color: navy;
}
</style>
<h1>Sports day</h1>
<p>Sports day is on Friday.</p>
<p class="note">Bring a hat.</p>
<p class="note">Bring water.</p>
<p class="note">Races start at 9 am.</p>
<style>
.note {
color: navy;
}
.big {
font-size: 24px;
}
</style>
<h1>Sports day</h1>
<p class="big">Sports day is on Friday.</p>
<p class="note">Bring a hat.</p>
<p class="note">Bring water.</p>
<p class="note">Races start at 9 am.</p>
<style>
.winner {
color: darkgreen;
}
.runner {
color: navy;
}
</style>
<h1>Race results</h1>
<p class="winner">First place: Owls</p>
<p class="runner">Second place: Hawks</p>
<p class="winner">First place: Eagles</p>
<p class="runner">Second place: Falcons</p>
Stretch: Give one paragraph a third class, `late`, in a third colour. Then give a list item the class `winner` and see that any tag can have one.
Support: Give students the Modify starter and do the first task together, then change the colour in the rule.
A rule .sale { color: red; } does nothing. Name two things that could be wrong.
No element has class="sale", or the name is spelt differently in the HTML. Another possibility is class=".sale" with the dot in the HTML.
Next lesson is a whole newsletter page that uses everything so far. Class idea: ask which parts of a school's real page might share a class.