The seed-swap cards shared a class. Now a makers’ fair program also needs unique destinations for its About, Projects, and Contact links. The starter in index.html supplies the main heading; add the navigation and section content below it.
Use class for a label that can appear on many elements. One element can carry several class names, separated by spaces.
<div class="card">Solar oven</div>
<div class="card">Seed library</div>
<div class="card featured">Repair map</div>
In CSS, a dot selects a class. This brief example uses the colors introduced earlier; you will apply selectors in depth in the CSS course:
.card {
color: darkgreen;
}
.featured {
background-color: gold;
}
Use id for one unique element on the page. An ID becomes an anchor target when a link uses # followed by that value.
<nav>
<a href="#hours">Opening hours</a>
<a href="#supplies">Supplies</a>
<a href="#location">Location</a>
</nav>
<section id="hours"><h2>Opening hours</h2></section>
<section id="supplies"><h2>Supplies</h2></section>
<section id="location"><h2>Location</h2></section>
This example is a workshop information page; the exercise uses different destinations for the fair. CSS uses # before an ID: #location { ... }. A class or ID is only a label until a stylesheet, link, or script uses it.
Run the page and select each navigation link. It should target the section with the same ID. A short page may not need to scroll, so check the matching values in the source too. If a link does not move, compare its href="#..." value with the section's id; they must match exactly.
class | id | |
|---|---|---|
| Uniqueness | Reusable | Must be unique |
| CSS selector | .classname | #idname |
| Multiple per element | Yes | Only one id per element |
| Use for | Styling groups | Unique landmarks, anchors |
Edit index.html, press Run to inspect your page, then Submit to check the tasks. You can submit after each step; later tasks may still be incomplete.
Build the fair program in the starter:
<nav> with readable links to #about, #projects, and #contact.<section> for each matching id. Each ID must occur only once on the page.<h2> label.<div class="card"> inside each section.class="card featured").Your fair page can now link directly to each stop and style every project card with one reusable label.
Apply multiple classes with a space: class="card featured large"
An id must be unique on the page — only one element can have any given id value.
Use class for styling multiple elements; use id for anchoring or uniquely identifying one element.
IDs double as anchor targets: <h2 id="contact"> can be linked with <a href="#contact">