class attribute gives CSS a way to select it.
3.3 Add this rule at the bottom of style.css:
.card {
background-color: white;
max-width: 640px;
margin: 0 auto;
padding: 24px;
border: 1px solid #cbd5e1;
border-radius: 12px;
}
3.4 Save and refresh.
Your content should appear inside a centred white card.
| Property | Purpose |
|---|---|
max-width |
Limits the content width while allowing it to become narrower. |
margin |
Controls space outside the border. Here, auto centres the card horizontally. |
padding |
Controls space between the content and the border. |
border |
Adds a line around the card. |
border-radius |
Rounds its corners. |
3.5 Change the card’s padding from 24px to 40px.
Predict what will change, then save and refresh. Restore it to 24px after checking.
Checkpoint: Explain why the CSS selector is .card, but the HTML says class="card" without a dot.
Step 4: Style your button and result — 15 minutes
4.1 Add these rules at the bottom of style.css:
button {
background-color: #1e40af;
color: white;
font-size: 18px;
padding: 12px 20px;
border: none;
border-radius: 8px;
cursor: pointer;
}
button:hover {
background-color: #172554;
}
button:focus-visible {
outline: 3px solid #111827;
outline-offset: 4px;
}
#result {
background-color: #dbeafe;
padding: 16px;
border-radius: 8px;
font-size: 22px;
font-weight: bold;
}
4.2 Save and refresh.
4.3 Move your pointer over the button. Its background should become darker.
4.4 Click the button. Your generated result should appear in the styled result area.
4.5 Press Tab to move keyboard focus through the controls. When the button has focus, you should see an outline. Press Enter to activate it.
Read the selectors:
| Selector | What it selects |
|---|---|
button |
Every button element. |
.card |
Elements with class="card". A class can be reused. |
#result |
The element with id="result". An ID should be unique on the page. |
button:hover |
A button while the pointer is over it. |
button:focus-visible |
A button when a visible focus indicator is needed, typically during keyboard navigation. |
Keep the IDs generate-button and result unchanged. Your JavaScript uses them to find the elements.
4.6 Personalise three things:
-
Change the heading colour.
-
Change the card’s corner rounding.
-
Change the result text size.
For each change, predict its effect, save, refresh, and compare.
Keep the text easy to read and the button clearly visible against its background.
Checkpoint: Your page has a styled button and result area. Clicking the button still generates an item.
Step 5: Test and explain — 10 minutes
5.1 Ask a partner to test your application.
| Test | Expected result |
|---|---|
| Click Generate several times | A generated value appears; random repeats are possible. |
| Move the pointer over the button | The button becomes darker. |
| Navigate using Tab | The selected button has a visible focus outline. |
| Activate the focused button with Enter | The generator runs. |
| Make the browser window narrower | The card fits within the window at a normal phone-sized width. |
| Follow the generator data link | JSON still appears at /api/generate. |
5.2 Create lesson4_notes.txt and answer:
-
Describe the purpose of CSS.
-
Identify the selector that styles the result paragraph.
-
Explain the difference between margin and padding.
-
Predict what would happen if the stylesheet link were removed.
-
Explain one design choice you made to help the user.
5.3 Show your teacher your working page and your answers.
If something goes wrong
| Problem | What to check |
|---|---|
| No styles appear | Check style.css and the link /static/style.css. Save both files and hard refresh. |
| Only the card styling is missing | Check class="card" in HTML and .card in CSS. |