CSS — The basics

Guide 01 / 4

CSS glossary

Give meaning to CSS terms by tying them to the recipe mini-blog.

Expected outcome :

Explain the concepts in your own words and recognise them in an example.

Reading
0%

01 · Getting your bearings before you start

Step 2/6 of the “À table !” running project, a recipe mini-blog. Go at your own pace: read, reproduce, modify, then check.

The path and the outcome of this step

Dress up the three recipes from the HTML course: readable cards, consistent colours and a grid that adapts to small screens. The same dataset runs through all six courses: Soupe de carottes (20 min), Salade de tomates (10 min), Tarte aux pommes (45 min).

01. HTML : structurer trois recettes dans une page sémantique.
02. CSS : rendre le blog lisible sur mobile et sur ordinateur.
03. JavaScript : filtrer les recettes sans recharger la page.
04. PHP : produire les pages depuis des tableaux et traiter un formulaire.
05. MySQL : conserver les recettes dans une base relationnelle.
06. PDO : lire et ajouter des recettes depuis PHP avec des requêtes préparées.
Remember :

Each course has four guides: glossary, essentials, workshop and resources. The complete files are at the end of the workshop.

Prerequisites and environment

Have finished HTML and have mini-blog/index.html with the classes entete, conteneur, recettes, recette, meta and pied. Keep the three reference recipes to compare results. No build tool is needed: the browser reads CSS directly.

mini-blog/
  index.html       # HTML, CSS et JavaScript
  style.css        # ajouté à l’étape CSS
  app.js           # ajouté à l’étape JavaScript
  public/          # pages PHP accessibles par HTTP
  includes/        # fonctions, connexion et données PHP
  database/        # scripts SQL
Remember :

Create this working folder separately from the Technipédia course files. The example paths are relative to mini-blog/. Do not replace the HTML page of this platform.

The method: understand, reproduce, transform

Read a sheet, then type its example. Explain what changes on screen. Change one thing at a time and compare with the expected result. Keep a copy of the previous step before moving on.

1. Je lis et je reformule.
2. Je reproduis dans mon mini-blog.
3. Je change une valeur ou une règle.
4. Je vérifie et j’explique le résultat.
Remember :

Short snippets illustrate a concept; only the files announced as complete are to be copied as they are. Fragments are not to be concatenated into a single file.

02 · Reading a stylesheet

CSS describes how to present an HTML document; it does not replace its meaning.

CSS, rule and declaration

A rule targets elements and contains property: value declarations. The browser applies the matching rules.

.recette {
  color: #29251f;
  padding: 1rem;
}
Remember :

Here, .recette is the selector; color and padding are properties.

Selector

A selector indicates the elements concerned. A name targets a tag, a dot a class, a hash an identifier.

h2 { color: #8b351b; }
.recette { padding: 1rem; }
#recettes { margin-block: 2rem; }

Cascade and specificity

Several declarations can target the same element. With equal origin, importance and layer, specificity decides between the rules; if it is equal, the last declaration wins.

.recette { color: brown; }
.recette { color: #29251f; }
Remember :

In this example, the text ends up #29251f. A selector with an id will be more specific than a simple class.

Inheritance

Some properties, such as color and font-family, are passed on to descendants. Others, such as margin and border, generally are not.

body { font-family: system-ui, sans-serif; }
button { font: inherit; }
Remember :

A button can have its own browser styles; font: inherit gives it its parent's font.

Box model

Each element occupies a box: content, inner padding, then border, then outer margin. Understanding these layers avoids guessing at spacing.

.recette {
  padding: 1rem;
  border: 1px solid #cbbba9;
  margin: 0;
}

Document flow

By default, blocks follow one another vertically. Inline elements, such as a link inside a paragraph, follow the text. Flexbox and Grid then organise certain zones.

<!-- Un h2, puis un paragraphe, puis une grille de cartes. -->

03 · Measuring and adapting

Start with a simple presentation, then adapt it to the content and the available width.

px, rem, em and percentage

px is a fixed CSS unit; rem depends on the root font size; em depends on the typographic context; % depends on the property and its reference element.

.recette { padding: 1rem; border-width: 1px; }
img { max-width: 100%; }
Remember :

A CSS pixel is not necessarily a physical pixel of the screen.

Flexbox

Flexbox lays out elements along a main axis, possibly over several lines. It suits navigation and filter controls.

nav { display: flex; flex-wrap: wrap; gap: 1rem; }

Grid

Grid organises elements in a grid of columns and rows. It is used for the recipe cards.

.recettes { display: grid; grid-template-columns: 1fr; gap: 1rem; }

Responsive and media query

A responsive page adapts to its available space. A media query applies rules when its condition is true.

@media (min-width: 48rem) {
  .recettes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
Remember :

Start with one column for small screens, then add three columns when there is enough room.

Pseudo-class and CSS variable

A pseudo-class targets a state, such as keyboard focus. A custom property, often called a CSS variable, centralises a reusable value.

:root { --accent: #8b351b; }
a { color: var(--accent); }
a:focus-visible { outline: 3px solid #185ea0; }