Guide 03 / 4
CSS workshop · À table !
Dress up the three recipes from the HTML course: readable cards, consistent colours and a grid that adapts to small screens.
Reproduce a working result, test it, then succeed at an exercise without copying.
01 · Dressing up the mini-blog
Start from the complete HTML file of step 1.
Step 1 · Create and link style.css
Add link in head, then reproduce the complete style.css file at the end of the workshop. Reload the browser.
Example
mini-blog/
├── index.html # ajouter link dans head
└── style.css
Expected result: a brown banner, a light background and white cards. The filter form stays hidden.
Step 2 · Understanding spacing
Inspect a card and spot padding and border in the box model. Temporarily disable padding: 1.25rem, then restore it.
Example
.recette { padding: 1.25rem; }
Expected result: without padding, the content almost touches the border; the gap between cards does not change.
Step 3 · Testing two widths
Shrink the window to about 360 px, then widen it to 1024 px. Observe the grid change. Also try a 200% zoom. Check that there is no horizontal overflow.
Example
Petit écran : une carte par ligne.
Grand écran : trois cartes par ligne.
The breakpoint is written in rem; its width in pixels depends on the browser's initial font size.
Step 4 · Testing keyboard access
Reload the page then press Tab. Activate Aller au contenu and go through the navigation links. Check that a focus outline is present.
Example
Tab : avancer.
Maj + Tab : reculer.
Entrée : activer un lien.
Expected result: the skip link appears on focus and the links remain recognisable.
02 · Modifying and diagnosing
Predict what will change before modifying the code.
Exercise · Add an intermediate width
Between 36rem and 48rem, show the recipes in two columns. Keep one column below and three above.
Example
Défi : écrire une media query min-width avant celle à 48rem.
Do not touch the HTML for this exercise.
Solution · A grid with three breakpoints
Add this rule before the media query at 48rem. From 48rem on, the existing rule comes after and replaces the number of columns.
Example
@media (min-width: 36rem) {
.recettes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Puis conserver la règle à 48rem du fichier complet. */
For the same selectors and true conditions, order decides between declarations of equal specificity.
Exercise · Change the palette without rewriting everything
Change only --accent, then observe headings, links and banner. Choose a colour dark enough for text on a light background and for the banner's white text.
Example
:root { --accent: #245b35; }
Expected: all the zones using var(--accent) change together. Check the contrast with a suitable tool.
Check · Reading the computed styles
In the browser tools, inspect an h3. Look for color in the computed styles. Trace back to the responsible rule and explain why it is applied.
Example
Question : si .recette h3 et h3 fixent deux couleurs, quel sélecteur est le plus spécifique ?
Answer: .recette h3, if the other cascade factors are identical.