Défi récapitulatif
Fait partie de la section Practical Frontend du Journey HTML de Coddy — leçon 5 sur 35.
Défi
FacileVotre tâche :
- Définir une variable globale pour la couleur d'arrière-plan
- Nom :
--main-bget choisissez la couleur que vous souhaitez. - Appliquez-la comme
background-colorpour le<body>.
- Nom :
- Définir une variable globale pour la police
- Nom :
--main-font - Appliquez-la comme
font-familypour le<body>.
- Nom :
- Définir une variable locale pour les cartes
- Nom :
--card-accent - Valeur :
tomato - Appliquez-la à :
- La couleur du
<h2>à l'intérieur de chaque carte - L'arrière-plan du
<button>à l'intérieur de chaque carte
- La couleur du
- Nom :
Essayez vous-même
<html>
<head>
<title>CSS Variables Recap Challenge</title>
<style>
/* Global Variables */
:root {
--primary-color: seagreen;
}
body {
margin: 0;
padding: 0;
}
header {
background-color: var(--primary-color);
color: white;
padding: 20px;
text-align: center;
}
header h1 {
margin: 0;
font-size: 2rem;
}
header p {
margin: 5px 0 0;
font-size: 1rem;
opacity: 0.9;
}
main {
padding: 20px;
display: grid;
gap: 20px;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}
.hero {
background: url('https://upload.wikimedia.org/wikipedia/commons/c/c0/Healthy_Food_-_Colourful_Fruit_and_Veg_-_50191699151.jpg') center/cover no-repeat;
color: white;
text-align: center;
padding: 30px 20px 50px 20px;
border-radius: 10px;
margin: 10px;
}
.hero button {
background-color: var(--primary-color);
padding: 10px 20px;
border: none;
border-radius: 5px;
font-weight: bold;
cursor: pointer;
color: white;
}
.card {
background: white;
border-radius: 10px;
padding: 15px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
justify-content: space-between;
}
.card h2 {
margin: 0 0 10px;
}
.card p {
font-size: 0.9rem;
color: #333;
}
.card button {
margin-top: 10px;
border: none;
padding: 8px 12px;
color: black;
border-radius: 5px;
font-weight: bold;
cursor: pointer;
}
footer {
background-color: #eee;
text-align: center;
padding: 15px;
font-size: 0.85rem;
margin-top: 20px;
}
</style>
</head>
<body>
<header>
<h1>Healthy Recipes</h1>
<p>Fresh, tasty, and colorful meals you can make at home</p>
</header>
<section class="hero">
<div class="hero-content">
<h2>Eat Healthy, Live Happy</h2>
<button>Explore Recipes</button>
</div>
</section>
<main>
<div class="card">
<h2>Avocado Salad</h2>
<p>A healthy salad with fresh avocado, tomatoes, and herbs.</p>
<button>Read Recipe</button>
</div>
<div class="card special">
<h2>Berry Smoothie</h2>
<p>Refreshing smoothie with blueberries, strawberries, and yogurt.</p>
<button>Read Recipe</button>
</div>
<div class="card">
<h2>Quinoa Bowl</h2>
<p>Nutritious quinoa with roasted vegetables and chickpeas.</p>
<button>Read Recipe</button>
</div>
</main>
<footer>
© 2025 Healthy Recipes. All rights reserved.
</footer>
</body>
</html>
Toutes les leçons de Practical Frontend
1Variables
VariablesUtiliser les variables CSSVariables pour les Design TokensVariables localesDéfi récapitulatif