Welcome
M1 | The Technical Fundamentals of the Web M2 | Advanced CMS M3 | UX/UI Products M4 | Advanced Prototyping M5 | Advanced Integration & Core Project Training Bonus
About Log In Create Account
LMS Pro LMS Pro
  • Welcome
  • Web Production & Interface Training
    • Module 1 — Technical Fundamentals of the Web
    • Module 2 — Advanced CMS
    • Module 3 — Product UX & UI
    • Module 4 — Advanced Prototyping
    • Module 5 — Advanced Integration & Capstone Project
    • Bonus Module
  • About
  • Log In
  • Sign Up
Skip to content

LMS Pro

LMS Pro — Your platform to learn, grow, succeed

Professional Training

UX/UI Designer

CSS Selectors: A Complete Guide to Targeting Your Elements

Posted on 6 January 202623 January 2026 By LMS Pro No Comments on Les Sélecteurs CSS : Guide Complet pour Cibler vos Éléments
Module 1 — Technical Fundamentals of the Web, Selectors & cascade

Les Sélecteurs CSS : Guide Complet pour Cibler vos Éléments

Apprenez à utiliser tous les types de sélecteurs CSS pour cibler précisément les éléments HTML. Des sélecteurs de type aux classes et IDs, maîtrisez l’art de la sélection CSS.

Level : Débutant à Intermédiaire

Durée : 40 minutes

Target audience: Développeurs web, Intégrateurs, Designers

Objectifs pédagogiques

  • Comprendre le rôle des sélecteurs CSS
  • Maîtriser les sélecteurs de type, classe et ID
  • Combiner plusieurs sélecteurs efficacement
  • Comprendre la spécificité CSS

Un sélecteur CSS est la première partie d’une règle CSS. Il indique au navigateur quels éléments HTML doivent recevoir les styles définis.

/* Le sélecteur est "h1" */
h1 {
color: blue;
font-size: 2em;
}

L’élément ou les éléments sélectionnés sont appelés le sujet du sélecteur.

Types de sélecteurs principaux

  • Sélecteur de type : cible un élément HTML (h1, p, div)
  • Sélecteur de classe : targets a class (.highlight)
  • Sélecteur d’ID : targets a unique identifier (#menu)

Le sélecteur de type cible tous les éléments d’un type donné dans le document.

HTML example

Main Title



Les légumes sont bons pour la santé.
<span>Mangez des carottes</span> et des épinards.



Fruits too: apples and oranges .

CSS avec sélecteurs de type

body {
font-family: sans-serif;
}

span {
background-color: yellow;
}

strong {
color: rebeccapurple;
}

em {
color: rebeccapurple;
}

h1 {
color: blue;
}

Résultat :

  • All the <span> will have a yellow background
  • All the <strong> And will be in purple
  • THE <h1> will be in blue

Le sélecteur de classe commence par un point (.) et cible tous les éléments possédant cette classe.

Syntax

.class-name {
/* styles */
}

Practical example

Important Title



Texte normal avec <span class="highlight">partie surlignée</span>.



Paragraphe entièrement mis en évidence.

.highlight {
background-color: yellow;
}

Cibler une classe sur un élément spécifique

/* Only spans with the highlight class */
span.highlight {
background-color: yellow;
}

/* Only h1 tags with the highlight class */
h1.highlight {
background-color: pink;
}

💡 Astuce : Un élément peut avoir plusieurs classes : <div class="box warning large">

Vous pouvez cibler des éléments ayant plusieurs classes simultanément en les enchaînant sans espace.

HTML example

Simple note.

Attention !

Hazard !

No style (notebox missing)

CSS avec sélecteurs combinés

.notebox {
border: 4px solid #666666;
padding: 0.5em;
margin: 0.5em;
}

/* Élément ayant les DEUX classes */
.notebox.warning {
border-color: orange;
font-weight: bold;
}

.notebox.danger {
border-color: red;
font-weight: bold;
}

⚠️ Important : The last <div class="danger"> will have no style because it lacks class notebox.

Le sélecteur d’ID commence par un dièse (#) et cible l’élément unique possédant cet ID.

Règle importante

Un ID doit être unique dans tout le document. Utilisez-le pour cibler un élément spécifique.

Example

Main Title


First paragraph.


Introductory paragraph.

#intro {
background-color: yellow;
}

h1#main-heading {
color: rebeccapurple;
}

When to use ID vs Class?

ID (#) Class (.)
Unique per page Réutilisable
Navigation, anchors Styles répétitifs
Haute spécificité Spécificité moyenne

Quand plusieurs règles ciblent le même élément, CSS utilise la spécificité pour déterminer laquelle appliquer.

Ordre de spécificité (du plus faible au plus fort)

  1. Sélecteurs de type (p, h1) – spécificité: 0,0,1
  2. Sélecteurs de classe (.special) – spécificité: 0,1,0
  3. Sélecteurs d’ID (#main) – spécificité: 1,0,0

Example of conflict

.special {
color: red;
}

p {
color: blue;
}

<p class="special">What color am I?</p>

Réponse : The text will be red car la classe a une spécificité plus élevée que le sélecteur de type.

The waterfall in action

p { color: red; }
p { color: blue; } /* Celui-ci gagne (dernière règle) */

💡 Règle : À spécificité égale, c’est la dernière règle déclarée qui s’applique.

Créez un système de cartes avec différents états :

HTML


Standard Card


Basic content.



Featured Card


<p>Mise en avant spéciale.</p>


Alert Map


Important message.



Hero Card


The most important one.


CSS

/* Common base */
.card {
border: 2px solid #ccc;
border-radius: 8px;
padding: 1rem;
margin: 1rem 0;
background: white;
}

/* Variants by class */
.card.featured {
border-color: gold;
background: #fffef0;
}

.card.warning {
border-color: red;
background: #fff0f0;
}

/* Unique style per ID */
#hero-card {
border-width: 4px;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

✅ Résultat : Un système modulaire où chaque carte peut combiner plusieurs styles.
Loading quiz...
Categories: Cascade Classes CSS ID Selectors Specificity

Post navigation

❮ Previous Post: CSS: Formatting Web Content – A Complete Guide
Next Post: CSS Typography: Mastering Text Formatting ❯

See also

Flexbox & Grid
CSS Flexbox: The Complete Guide to Flexible Layout
January 6, 2026
Module 1 — Technical Fundamentals of the Web
Advanced HTML
January 23, 2026

LMS Pro LMS Pro is an educational platform dedicated to Professional Training. LMS Pro 2026 All rights reserved

You must log in

Forgot password?
No account yet., click here
LMS Pro

Create an account

Fill in this information

Already have an account? Log in
LMS Pro
English
French