TP CSS3 - Corrigé Complet

Exercice 1 : Sélecteurs

1. Sélectionner tous les liens dans la navigation
nav.main-nav a { }
2. Sélectionner uniquement le lien actif
nav.main-nav a.active { }
3. Sélectionner l'article avec la classe featured
article.featured { }
4. Premier paragraphe de chaque article
article p:first-of-type { }
5. Éléments li pairs
li:nth-child(even) { }

Spécificité

p < .text < p.text < #main < #main .text p Même spécificité → la dernière règle gagne !important → à éviter car casse la logique CSS

Exercice 2 : Box Model

Largeur totale (content-box)
350px
Largeur totale (border-box)
300px
Reset box-sizing
* { box-sizing: border-box; }

Centrage

body { display: flex; justify-content: center; align-items: center; height: 100vh; }

Flexbox - Navbar

.navbar { display: flex; justify-content: space-between; align-items: center; }

Flexbox - Cartes

.card { display: flex; flex-direction: column; justify-content: space-between; }

Grid Responsive

grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));

Grid Layout

grid-template-areas: "header header" "sidebar main" "footer footer";

Responsive Design

@media (min-width: 768px) { } @media (min-width: 1024px) { }

Variables CSS

:root { --color-bg: white; } [data-theme="dark"] { --color-bg: black; }

Animations

@keyframes spin { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } }

Quiz

1. b) #header a 2. b) 200px 3. c) justify-content + align-items 4. b) 1 fraction 5. b) min-width