Calculator tutorial steps
Thème :
Intermédiaire
1 vues ·3/5 leçonsÉtape 3 : CSS - Le Thème “Vert Matrix”
Voici la partie demandée : un design aux couleurs Vert et Vert Sombre.
1. Variables et Reset
Ouvrez style.css et commencez par définir votre palette.
:root {
/* Palette Matrix / Hacker Green */
--bg-body: #051a10; /* Vert très très sombre (presque noir) */
--bg-calc: #0a2919; /* Vert sombre pour le corps de la calculatrice */
--screen-bg: #143d26; /* Fond de l'écran */
--text-primary: #4ade80; /* Vert clair lumineux (Néon) */
--text-secondary: #22c55e; /* Vert standard */
--btn-bg: #113321; /* Touche standard */
--btn-hover: #166534; /* Touche survol */
--btn-op-bg: #15803d; /* Touche opération */
--btn-eq-bg: #4ade80; /* Touche Égal (la plus brillante) */
--btn-eq-text: #064e3b; /* Texte foncé sur bouton clair */
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: var(--bg-body);
font-family: 'Roboto Mono', monospace;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
2. La Calculatrice (Grid)
.calculator {
background: var(--bg-calc);
width: 350px;
padding: 20px;
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0, 255, 100, 0.1); /* Lueur verte subtile */
border: 1px solid #166534;
}
/* L'écran */
.display {
background: var(--screen-bg);
min-height: 100px;
border-radius: 10px;
display: flex;
flex-direction: column;
align-items: flex-end; /* Texte aligné à droite */
justify-content: space-around;
padding: 10px 20px;
margin-bottom: 20px;
word-break: break-all;
word-wrap: break-word;
}
.previous-operand {
color: var(--text-secondary);
font-size: 1rem;
height: 24px;
}
.current-operand {
color: var(--text-primary);
font-size: 2rem;
font-weight: 700;
text-shadow: 0 0 5px rgba(74, 222, 128, 0.5); /* Effet néon */
}
3. La Grille des Touches
C’est ici que display: grid fait des merveilles.
.keys-grid {
display: grid;
grid-template-columns: repeat(4, 1fr); /* 4 colonnes identiques */
gap: 10px;
}
.btn {
height: 60px;
border-radius: 10px;
border: none;
background: var(--btn-bg);
color: var(--text-primary);
font-size: 1.25rem;
font-family: inherit;
cursor: pointer;
transition: all 0.2s;
border: 1px solid transparent;
}
/* Effets au survol */
.btn:hover {
background: var(--btn-hover);
border-color: var(--text-primary);
}
/* Bouton Opérateur */
.btn-op {
background: var(--btn-op-bg);
color: white;
}
/* Bouton Égal */
.btn-eq {
background: var(--btn-eq-bg);
color: var(--btn-eq-text);
font-weight: bold;
box-shadow: 0 0 10px var(--text-primary); /* Brille plus fort */
}
/* Boutons qui prennent 2 places */
.span-two {
grid-column: span 2;
}
Et voilà ! Vous avez une calculatrice au look cyber-punk / hacker vert.
Prêt à passer à la suite ?
Vous avez terminé cette leçon sur Étape 3 : CSS - Le Thème "Vert Matrix". Continuez votre apprentissage avec la prochaine leçon ou explorez d'autres formations.