🎯 Exemples visuels interactifs

📗 Chapitre 31 : Pseudo-classes ordinales

151 Nième du type :nth-of-typeلا

📖 Définition : Sélectionne le n-ième élément d'un type spécifique parmi ses frères.

p:nth-of-type(2) {
    background: #fdebd0;
    padding: 5px;
}
✨ RÉSULTAT

Paragraphe 1

✓ Paragraphe 2 (ciblé)

Paragraphe 3

152 Nième depuis la fin :nth-last-of-typeلا

📖 Définition : Sélectionne le n-ième élément en partant de la fin d'un type spécifique.

p:nth-last-of-type(1) {
    background: #d5f5e3;
    padding: 5px;
}
✨ RÉSULTAT

Paragraphe 1

Paragraphe 2

✓ Dernier paragraphe (ciblé)

153 Formule arithmétique :nth-child(an+b)

📖 Définition : Sélectionne les éléments selon une formule arithmétique (3n, 2n+1, etc.).

li:nth-child(3n+1) {
    background: #e8f4fd;
    padding: 5px;
}
✨ RÉSULTAT (3n+1 : 1, 4, 7...)
  • 1. Élément 1 ✓
  • 2. Élément 2
  • 3. Élément 3
  • 4. Élément 4 ✓
  • 5. Élément 5
  • 6. Élément 6
  • 7. Élément 7 ✓

154 Formule depuis la fin :nth-last-child(an+b)

📖 Définition : Sélectionne les éléments depuis la fin selon une formule arithmétique.

li:nth-last-child(2n+1) {
    background: #fef3c7;
    padding: 5px;
}
✨ RÉSULTAT (depuis la fin)
  • 1. Premier
  • 2. Deuxième
  • 3. Troisième ✓
  • 4. Quatrième
  • 5. Cinquième ✓
  • 6. Sixième
  • 7. Septième ✓

155 Enfant unique :only-child

📖 Définition : Sélectionne l'élément qui est l'unique enfant de son parent.

li:only-child {
    color: #16a34a;
    font-weight: bold;
}
✨ RÉSULTAT
  • ✓ Seul élément de la liste
  • Premier élément
  • Deuxième élément

📘 Chapitre 32 : Pseudo-classes de formulaire avancées

156 Valeur par défaut :default

📖 Définition : Sélectionne les éléments de formulaire qui sont sélectionnés par défaut.

input:default {
    box-shadow: 0 0 0 2px #3498db;
}
✨ RÉSULTAT

157 Activé :enabled

📖 Définition : Sélectionne les champs de formulaire activés.

input:enabled {
    border: 2px solid #2ecc71;
}
✨ RÉSULTAT

158 Lecture seule :read-only

📖 Définition : Sélectionne les champs en lecture seule.

input:read-only {
    background: #f8f9fa;
    border: 1px dashed #95a5a6;
}
✨ RÉSULTAT

159 Lecture/écriture :read-write

📖 Définition : Sélectionne les champs modifiables par l'utilisateur.

input:read-write {
    border: 2px solid #3498db;
}
✨ RÉSULTAT

160 Placeholder visible :placeholder-shown

📖 Définition : Sélectionne les champs dont le placeholder est visible (champ vide).

input:placeholder-shown {
    border-color: #95a5a6;
    background: #f8f9fa;
}
✨ RÉSULTAT

📙 Chapitre 33 : Sélecteurs de ressources

161 Élément défini :defined

📖 Définition : Sélectionne les éléments personnalisés qui ont été définis.

custom-element:defined {
    border: 2px solid #2ecc71;
    padding: 10px;
}
✨ RÉSULTAT
Élément personnalisé défini

162 Plein écran :fullscreen

📖 Définition : Sélectionne un élément lorsqu'il est en mode plein écran.

.fullscreen-demo:fullscreen {
    background: #2c3e66;
    color: white;
}
✨ RÉSULTAT
Simulation d'élément en plein écran

163 Image dans l'image :picture-in-picture

📖 Définition : Sélectionne une vidéo en mode picture-in-picture.

video:picture-in-picture {
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
✨ RÉSULTAT
Vidéo en mode PiP (simulation)

164 Hôte du composant :host

📖 Définition : Sélectionne l'élément hôte d'un Web Component.

:host {
    display: block;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 10px;
}
✨ RÉSULTAT
Composant Web (hôte)

165 Élément distribué ::slotted()

📖 Définition : Style les éléments distribués dans un slot d'un Web Component.

::slotted(p) {
    color: #3498db;
    font-weight: bold;
}
✨ RÉSULTAT
Paragraphe distribué dans un slot

📒 Chapitre 34 : Pseudo-classes de contenu

166 Élément vide :empty

📖 Définition : Sélectionne les éléments sans enfant (pas de texte ni d'élément).

div:empty {
    background: #fdebd0;
    border: 2px dashed #e74c3c;
    padding: 20px;
}
✨ RÉSULTAT
Ce div contient du texte
 

167 Élément blanc :blank

📖 Définition : Sélectionne les éléments contenant uniquement des espaces ou rien.

textarea:blank {
    border: 2px solid #e74c3c;
}
✨ RÉSULTAT

168 Cible d'ancre :target

📖 Définition : Sélectionne l'élément ciblé par l'URL (ancre).

section:target {
    background: #f9e79f;
    border-left: 4px solid #f1c40f;
}
✨ RÉSULTAT

👉 Aller à la section cible

Section cible !

169 Cible à l'intérieur :target-within

📖 Définition : Sélectionne un élément lorsqu'un de ses enfants est la cible.

div:target-within {
    background: #d5f5e3;
    border-left: 4px solid #2ecc71;
}
✨ RÉSULTAT
Contenu cible à l'intérieur

170 Tout lien :any-link

📖 Définition : Sélectionne tous les liens (qu'ils soient visités ou non).

a:any-link {
    text-decoration: none;
    font-weight: bold;
}

📕 Chapitre 35 : Sélecteurs modernes (CSS4+)

171 Élément modal :modal

📖 Définition : Sélectionne un élément lorsqu'il est dans un état modal.

dialog:modal {
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
✨ RÉSULTAT
Exemple de modal

172 Popover ouvert :popover-open

📖 Définition : Sélectionne les éléments popover lorsqu'ils sont ouverts.

.popover:popover-open {
    animation: fadeIn 0.3s ease;
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
✨ RÉSULTAT
Popover ouvert (simulation)

173 Élément racine :root

📖 Définition : Sélectionne l'élément racine (<html>). Utile pour les variables CSS.

:root {
    --primary-color: #3498db;
    --secondary-color: #2ecc71;
}
✨ RÉSULTAT
Texte utilisant la variable --primary-color

174 Portée :scope

📖 Définition : Représente l'élément qui sert de portée/référence.

.parent :scope {
    border-left: 3px solid #3498db;
    padding-left: 10px;
}
✨ RÉSULTAT
Élément avec portée

175 Langue :lang()

📖 Définition : Sélectionne les éléments selon leur langue.

p:lang(fr) {
    quotes: "«" "»";
}
p:lang(en) {
    quotes: "“" "”";
}
✨ RÉSULTAT

« Bonjour le monde ! »

“Hello world!”

📝 Tableau récapitulatif (Sélecteurs 151 à 175)

📗 Chapitre 31 : :nth-of-type, :nth-last-of-type, :nth-child(an+b), :nth-last-child(an+b), :only-child

📘 Chapitre 32 : :default, :enabled, :read-only, :read-write, :placeholder-shown

📙 Chapitre 33 : :defined, :fullscreen, :picture-in-picture, :host, ::slotted()

📒 Chapitre 34 : :empty, :blank, :target, :target-within, :any-link

📕 Chapitre 35 : :modal, :popover-open, :root, :scope, :lang()