Académique Documents
Professionnel Documents
Culture Documents
Exemple
p{
text-align: center; Ici, tous les éléments <p> de la page seront alignés au
color: red; centre, avec une couleur de texte rouge:
}
Exemple: Sélecteur d’élément
EXERCICES CSS
<!DOCTYPE html>
<html>
<head>
<style>
p{
text-align: center;
color: red; Every paragraph will be affected by the style.
} Me too!
</style> And me!
</head>
<body>
</body>
</html>
EXERCICES CSS
Exemple
#para1 {
text-align: center;
color: red;
}
Exemple: Sélecteur id EXERCICES CSS
<!DOCTYPE html>
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
EXERCICES CSS
3- Sélecteur par classe: Le sélecteur de classe sélectionne les éléments HTML avec un
attribut de classe spécifique. Pour sélectionner des éléments avec une classe spécifique, il
faut mettre un point (.), Suivi du nom de la classe.
Exemple.
Dans cet exemple, tous les éléments HTML avec class = "center" seront rouges et alignés au centre:
.center {
text-align: center;
color: red;
}
EXERCICES CSS
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: red; Red and center-aligned heading
} Red and center-aligned paragraph.
</style>
</head>
<body>
</body>
</html>
EXERCICES CSS
Exercice 1
Mettre la couleur de tous les éléments <p> en « rouge".
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
EXERCICES CSS
Exercice 2
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p id="para1">This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
EXERCICES CSS
Exercice 3
Mettre la couleur de l’élément identifié par class "colortext", en “rouge".
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p class="colortext">This is another paragraph.</p>
<p class="colortext">This is also a paragraph.</p>
</body>
</html>
Exercice 4 EXERCICES CSS
Mettre la couleur des éléments <p> et <h1> en rouge, grouper les sélecteurs pour
minimiser le code
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<h1>This is a heading</h1>
<h2>This is a smaller heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Exercice 5
Ajouter une feuille de style externe en utilisant URL: "mystyle.css".
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Exercice 6
A l'aide d'une feuille de style interne, donnez la couleur à l’arrière-plan "background-
color: lin" pour la page
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Exercice 7
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Exercice 8
Supprimez tous les styles, à l'exception de la feuille de style externe "mystyle.css".
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
p{
color: red;
}
</style>
</head>
<body style="background-color: lightcyan">
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Solution Exercice 1
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: red;
}
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Solution Exercice 2
<!DOCTYPE html>
<html>
<head>
<style>
#para1 {
color: red;
}
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p id="para1">This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Solution Exercice 3
<!DOCTYPE html>
<html>
<head>
<style>
.colortext {
color: red;
}
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p class="colortext">This is another paragraph.</p>
<p class="colortext">This is also a paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Solution Exercice 4
<!DOCTYPE html>
<html>
<head>
<style>
h1, p {
color: red;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<h2>This is a smaller heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Solution Exercice 5
Ajouter une feuille de style externe en utilisant URL: "mystyle.css".
!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="mystyle.css">
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Solution Exercice 6
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
}
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Solution Exercice 7
<!DOCTYPE html>
<html>
<head>
</head>
<body style="background-color: linen">
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Exercice 8
Supprimez tous les styles, à l'exception de la feuille de style externe "mystyle.css".
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
p{
color: red;
}
</style>
</head>
<body style="background-color: lightcyan">
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
SOLUTIONS EXERCICES CSS
Exercice 8 Solution
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="mystyle.css">
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>