Cours HTML et CSS · Module 6: Animations CSS
Projet principal - Galerie de portfolio 3D animée
Dans cette leçon5
Les chambres funéraires égyptiennes racontaient des histoires image après image, et le visiteur muni d'une torche les découvrait l'une après l'autre. Ton portfolio peut fonctionner de la même façon : un cube tourne dans l'espace, et les cartes de projets entrent en scène l'une après l'autre. Dans ce projet, nous allons créer une galerie 3D spectaculaire en utilisant uniquement HTML et CSS. La galerie inclura des animations @keyframes avancées, des transformations 3D, des effets de survol et des diaporamas automatiques. Le projet illustre toutes les techniques d'animation CSS de ce module sans utiliser JavaScript.
Description du projet
Notre galerie 3D inclura :
- Carrousel 3D - un cube en rotation avec des images
- Cartes de projet animées - avec effets de survol et transformations
- Diaporama automatique - en utilisant uniquement CSS
- Effets de particules - arrière-plan animé et décorations
- Menu de navigation animé - avec effets de transition
- Écran de chargement - avec des animations avancées
La galerie 3D étape par étape
1. La scène 3D
Tout commence par la scène. perspective, appliquée au parent, fixe la distance entre le spectateur et l'écran et donne de la profondeur à ses enfants, tandis que transform-style: preserve-3d permet aux faces du cube de vivre dans un même espace :
body {
perspective: 1000px;
}
.cube-container {
transform-style: preserve-3d;
}
.front { transform: translateZ(150px); }
.back { transform: rotateY(180deg) translateZ(150px); }Chaque face est tournée puis avancée de la moitié de la largeur du cube, soit 150 pixels. perspective agit sur les enfants de l'élément, or le cube est un petit-enfant de body, donc dans ce code il tourne sans effet de raccourci perspectif. Ajoute perspective: 1000px à .hero et compare la profondeur.
2. Les images clés de la rotation
La rotation est décrite par la règle @keyframes, de zéro jusqu'à 360 degrés complets autour des deux axes à la fois :
@keyframes rotateCube {
0% { transform: rotateX(0) rotateY(0); }
100% { transform: rotateX(360deg) rotateY(360deg); }
}rotateY() fait tourner l'élément autour de l'axe vertical, comme un carrousel, et rotateX() autour de l'axe horizontal, comme une noria d'irrigation sur les rives du Nil.
3. L'animation en mouvement
La rotation est lancée par la déclaration animation placée sur le conteneur du cube, avec une durée stockée dans une variable CSS :
.cube-container {
animation: rotateCube var(--animation-duration) linear infinite;
}La variable --animation-duration vaut 20s dans :root, linear maintient une vitesse constante, et infinite fait tourner le cube sans fin.
4. Les effets de survol sur les cartes
Les cartes de projets se soulèvent en douceur sous le curseur, et elles ont leur propre animation à l'arrivée sur la page :
.project-card {
transition: transform 0.6s ease;
animation: cardAppear 0.8s ease-out backwards;
}
.project-card:hover {
transform: translateY(-10px) rotateX(5deg);
}Le mode backwards est essentiel. Une animation avec forwards maintiendrait la carte sur la dernière image clé et écraserait son transform, donc l'effet de survol ne fonctionnerait pas. Avec backwards, l'animation rend la carte à ses styles habituels une fois terminée, et transition peut alors la soulever.
5. La séquence d'entrée
Enfin, animation-delay fait apparaître les cartes l'une après l'autre, et non toutes en même temps :
.project-card:nth-child(1) { animation-delay: 0.1s; }
.project-card:nth-child(2) { animation-delay: 0.2s; }
.project-card:nth-child(3) { animation-delay: 0.3s; }Chaque carte démarre 0,1 seconde après la précédente. Grâce à backwards, elle attend son tour invisible et inclinée, au lieu d'apparaître brièvement avant le départ.
Bonus : un diaporama sans JavaScript
Le diaporama automatique fonctionne grâce à des images clés qui répètent la même valeur. L'écriture 0%, 20% { transform: translateX(0); } fait que la diapositive reste immobile pendant les premiers 20% du cycle, puis se décale de toute sa largeur et attend de nouveau. Avec un cycle de quinze secondes, chaque diapositive s'arrête pendant 3 secondes.
Trouve les deux défauts
Deux pièges se cachent dans le code complet. Le premier se trouve dans la section des compétences : :nth-child compte toute la fratrie, et le premier enfant de la section est le titre h2. La règle .skill-item:nth-child(1) ne cible donc rien, les délais et les largeurs sont décalés d'un cran, et la dernière barre reçoit la largeur complète. :nth-of-type(), qui ne compte que les éléments du même type, corrige ce problème. Le second concerne le timing : l'écran de chargement disparaît au bout de cinq secondes, alors que les cartes terminent leur entrée au bout d'une seconde et demie, donc toute la séquence se joue derrière le rideau.
Code complet du projet
Les styles se trouvent dans la balise style, il suffit donc d'enregistrer tout le fichier sous le nom index.html et de l'ouvrir dans un navigateur :
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Galerie de portfolio 3D animée</title>
<style>
/* Reset et variables */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary-color: #6c5ce7;
--secondary-color: #a29bfe;
--accent-color: #fd79a8;
--dark-color: #2d3436;
--light-color: #dfe6e9;
--animation-duration: 20s;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
overflow-x: hidden;
perspective: 1000px;
}
/* Arrière-plan animé */
@keyframes gradientShift {
0%, 100% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
}
body {
background-size: 200% 200%;
animation: gradientShift 15s ease infinite;
}
/* Écran de chargement */
.loading-screen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #2d3436;
display: flex;
justify-content: center;
align-items: center;
z-index: 9999;
animation: hideLoading 3s ease-out forwards;
animation-delay: 2s;
}
@keyframes hideLoading {
to {
opacity: 0;
pointer-events: none;
}
}
.loader {
width: 100px;
height: 100px;
position: relative;
}
.loader-circle {
position: absolute;
width: 100%;
height: 100%;
border: 4px solid transparent;
border-top-color: var(--primary-color);
border-radius: 50%;
animation: rotate 1s linear infinite;
}
.loader-circle:nth-child(2) {
width: 80%;
height: 80%;
top: 10%;
left: 10%;
border-top-color: var(--secondary-color);
animation-duration: 0.8s;
animation-direction: reverse;
}
.loader-circle:nth-child(3) {
width: 60%;
height: 60%;
top: 20%;
left: 20%;
border-top-color: var(--accent-color);
animation-duration: 0.6s;
}
@keyframes rotate {
to { transform: rotate(360deg); }
}
/* Navigation */
.navbar {
position: fixed;
top: 0;
width: 100%;
background: rgba(45, 52, 54, 0.9);
backdrop-filter: blur(10px);
padding: 1rem 2rem;
z-index: 1000;
animation: slideDown 0.8s ease-out;
}
@keyframes slideDown {
from {
transform: translateY(-100%);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.nav-container {
max-width: 1200px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-size: 2rem;
font-weight: bold;
color: white;
animation: logoGlow 3s ease-in-out infinite;
}
@keyframes logoGlow {
0%, 100% {
text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}
50% {
text-shadow: 0 0 20px rgba(255, 255, 255, 0.8),
0 0 30px var(--accent-color);
}
}
.nav-links {
display: flex;
gap: 2rem;
list-style: none;
}
.nav-link {
color: white;
text-decoration: none;
position: relative;
transition: color 0.3s ease;
}
.nav-link::after {
content: '';
position: absolute;
bottom: -5px;
left: 0;
width: 0;
height: 2px;
background: var(--accent-color);
transition: width 0.3s ease;
}
.nav-link:hover::after {
width: 100%;
}
/* Section Hero avec cube 3D */
.hero {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
position: relative;
margin-top: -60px;
}
.cube-container {
width: 300px;
height: 300px;
position: relative;
transform-style: preserve-3d;
animation: rotateCube var(--animation-duration) linear infinite;
}
@keyframes rotateCube {
0% { transform: rotateX(0) rotateY(0); }
100% { transform: rotateX(360deg) rotateY(360deg); }
}
.cube-face {
position: absolute;
width: 300px;
height: 300px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 2px solid rgba(255, 255, 255, 0.2);
display: flex;
justify-content: center;
align-items: center;
font-size: 3rem;
color: white;
}
.cube-face::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(135deg,
transparent 0%,
var(--primary-color) 50%,
transparent 100%);
opacity: 0;
animation: shimmer 3s ease-in-out infinite;
}
@keyframes shimmer {
0%, 100% { opacity: 0; }
50% { opacity: 0.5; }
}
.front { transform: translateZ(150px); }
.back { transform: rotateY(180deg) translateZ(150px); }
.left { transform: rotateY(-90deg) translateZ(150px); }
.right { transform: rotateY(90deg) translateZ(150px); }
.top { transform: rotateX(90deg) translateZ(150px); }
.bottom { transform: rotateX(-90deg) translateZ(150px); }
/* Particules animées */
.particles {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
overflow: hidden;
}
.particle {
position: absolute;
width: 4px;
height: 4px;
background: white;
border-radius: 50%;
animation: float linear infinite;
}
@keyframes float {
from {
transform: translateY(100vh) rotate(0deg);
opacity: 0;
}
10% {
opacity: 1;
}
90% {
opacity: 1;
}
to {
transform: translateY(-100vh) rotate(360deg);
opacity: 0;
}
}
.particle:nth-child(1) { left: 10%; animation-duration: 15s; animation-delay: 0s; }
.particle:nth-child(2) { left: 20%; animation-duration: 20s; animation-delay: 2s; }
.particle:nth-child(3) { left: 30%; animation-duration: 18s; animation-delay: 4s; }
.particle:nth-child(4) { left: 40%; animation-duration: 22s; animation-delay: 1s; }
.particle:nth-child(5) { left: 50%; animation-duration: 16s; animation-delay: 3s; }
.particle:nth-child(6) { left: 60%; animation-duration: 19s; animation-delay: 5s; }
.particle:nth-child(7) { left: 70%; animation-duration: 21s; animation-delay: 2s; }
.particle:nth-child(8) { left: 80%; animation-duration: 17s; animation-delay: 4s; }
.particle:nth-child(9) { left: 90%; animation-duration: 23s; animation-delay: 1s; }
.particle:nth-child(10) { left: 95%; animation-duration: 14s; animation-delay: 6s; }
/* Galerie de projets */
.gallery {
padding: 100px 2rem;
max-width: 1200px;
margin: 0 auto;
}
.gallery-title {
text-align: center;
font-size: 3rem;
color: white;
margin-bottom: 3rem;
animation: fadeInUp 1s ease-out;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.projects-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
}
.project-card {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
overflow: hidden;
position: relative;
height: 400px;
transform-style: preserve-3d;
transition: transform 0.6s ease;
animation: cardAppear 0.8s ease-out backwards;
}
.project-card:nth-child(1) { animation-delay: 0.1s; }
.project-card:nth-child(2) { animation-delay: 0.2s; }
.project-card:nth-child(3) { animation-delay: 0.3s; }
.project-card:nth-child(4) { animation-delay: 0.4s; }
.project-card:nth-child(5) { animation-delay: 0.5s; }
.project-card:nth-child(6) { animation-delay: 0.6s; }
@keyframes cardAppear {
from {
opacity: 0;
transform: rotateY(90deg) scale(0.8);
}
to {
opacity: 1;
transform: rotateY(0) scale(1);
}
}
.project-card:hover {
transform: translateY(-10px) rotateX(5deg);
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}
.project-image {
width: 100%;
height: 60%;
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
position: relative;
overflow: hidden;
}
.project-image::before {
content: '▣';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 4rem;
opacity: 0.5;
}
.project-wave {
position: absolute;
bottom: -50%;
left: -50%;
width: 200%;
height: 200%;
background: rgba(255, 255, 255, 0.1);
border-radius: 40%;
animation: wave 10s linear infinite;
}
@keyframes wave {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.project-content {
padding: 1.5rem;
color: white;
}
.project-title {
font-size: 1.5rem;
margin-bottom: 0.5rem;
}
.project-description {
opacity: 0.8;
line-height: 1.6;
}
/* Diaporama automatique */
.slider {
width: 100%;
height: 500px;
margin: 100px auto;
overflow: hidden;
position: relative;
background: rgba(255, 255, 255, 0.05);
border-radius: 20px;
}
.slider-wrapper {
display: flex;
animation: slide 15s ease-in-out infinite;
}
@keyframes slide {
0%, 20% { transform: translateX(0); }
25%, 45% { transform: translateX(-100%); }
50%, 70% { transform: translateX(-200%); }
75%, 95% { transform: translateX(-300%); }
100% { transform: translateX(0); }
}
.slide {
min-width: 100%;
height: 500px;
display: flex;
align-items: center;
justify-content: center;
font-size: 3rem;
color: white;
position: relative;
}
.slide:nth-child(1) { background: linear-gradient(135deg, #667eea, #764ba2); }
.slide:nth-child(2) { background: linear-gradient(135deg, #f093fb, #f5576c); }
.slide:nth-child(3) { background: linear-gradient(135deg, #4facfe, #00f2fe); }
.slide:nth-child(4) { background: linear-gradient(135deg, #fa709a, #fee140); }
.slide-content {
text-align: center;
animation: slideContent 15s ease-in-out infinite;
}
@keyframes slideContent {
0%, 20% { opacity: 1; transform: scale(1); }
22%, 25% { opacity: 0; transform: scale(0.8); }
25%, 45% { opacity: 1; transform: scale(1); }
47%, 50% { opacity: 0; transform: scale(0.8); }
50%, 70% { opacity: 1; transform: scale(1); }
72%, 75% { opacity: 0; transform: scale(0.8); }
75%, 95% { opacity: 1; transform: scale(1); }
97%, 100% { opacity: 0; transform: scale(0.8); }
}
/* Indicateurs du diaporama */
.slider-indicators {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 10px;
}
.indicator {
width: 50px;
height: 4px;
background: rgba(255, 255, 255, 0.3);
position: relative;
overflow: hidden;
}
.indicator::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: white;
animation: indicatorFill 15s ease-in-out infinite;
}
.indicator:nth-child(1)::before { animation-delay: 0s; }
.indicator:nth-child(2)::before { animation-delay: 3.75s; }
.indicator:nth-child(3)::before { animation-delay: 7.5s; }
.indicator:nth-child(4)::before { animation-delay: 11.25s; }
@keyframes indicatorFill {
0% { left: -100%; }
25% { left: 0; }
26%, 100% { left: 100%; }
}
/* Section des compétences avec animations */
.skills {
padding: 100px 2rem;
max-width: 1200px;
margin: 0 auto;
}
.skills-title {
text-align: center;
font-size: 3rem;
color: white;
margin-bottom: 3rem;
}
.skill-item {
margin-bottom: 2rem;
opacity: 0;
animation: skillAppear 0.8s ease-out forwards;
}
.skill-item:nth-child(1) { animation-delay: 0.2s; }
.skill-item:nth-child(2) { animation-delay: 0.4s; }
.skill-item:nth-child(3) { animation-delay: 0.6s; }
.skill-item:nth-child(4) { animation-delay: 0.8s; }
@keyframes skillAppear {
from {
opacity: 0;
transform: translateX(-50px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.skill-name {
color: white;
margin-bottom: 0.5rem;
}
.skill-bar {
width: 100%;
height: 20px;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
overflow: hidden;
}
.skill-progress {
height: 100%;
background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
border-radius: 10px;
animation: fillBar 2s ease-out forwards;
animation-delay: 1s;
transform-origin: left;
transform: scaleX(0);
}
@keyframes fillBar {
to { transform: scaleX(1); }
}
.skill-item:nth-child(1) .skill-progress { width: 90%; }
.skill-item:nth-child(2) .skill-progress { width: 85%; }
.skill-item:nth-child(3) .skill-progress { width: 95%; }
.skill-item:nth-child(4) .skill-progress { width: 80%; }
/* Pied de page avec animation */
.footer {
padding: 50px 2rem;
text-align: center;
color: white;
position: relative;
overflow: hidden;
}
.footer::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 2px;
background: linear-gradient(90deg,
transparent,
var(--accent-color),
transparent);
animation: footerLine 3s linear infinite;
}
@keyframes footerLine {
to { left: 100%; }
}
/* Responsivité */
@media (max-width: 768px) {
.cube-container {
width: 200px;
height: 200px;
}
.cube-face {
width: 200px;
height: 200px;
font-size: 2rem;
}
.front { transform: translateZ(100px); }
.back { transform: rotateY(180deg) translateZ(100px); }
.left { transform: rotateY(-90deg) translateZ(100px); }
.right { transform: rotateY(90deg) translateZ(100px); }
.top { transform: rotateX(90deg) translateZ(100px); }
.bottom { transform: rotateX(-90deg) translateZ(100px); }
.gallery-title,
.skills-title {
font-size: 2rem;
}
.nav-links {
display: none;
}
}
</style>
</head>
<body>
<!-- Écran de chargement -->
<div class="loading-screen">
<div class="loader">
<div class="loader-circle"></div>
<div class="loader-circle"></div>
<div class="loader-circle"></div>
</div>
</div>
<!-- Particules d'arrière-plan animées -->
<div class="particles">
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
</div>
<!-- Navigation -->
<nav class="navbar">
<div class="nav-container">
<div class="logo">Portfolio 3D</div>
<ul class="nav-links">
<li><a href="#home" class="nav-link">Accueil</a></li>
<li><a href="#projects" class="nav-link">Projets</a></li>
<li><a href="#skills" class="nav-link">Compétences</a></li>
<li><a href="#contact" class="nav-link">Contact</a></li>
</ul>
</div>
</nav>
<!-- Section Hero avec cube 3D -->
<section class="hero" id="home">
<div class="cube-container">
<div class="cube-face front">Front</div>
<div class="cube-face back">Back</div>
<div class="cube-face left">Left</div>
<div class="cube-face right">Right</div>
<div class="cube-face top">Top</div>
<div class="cube-face bottom">Bottom</div>
</div>
</section>
<!-- Diaporama automatique -->
<div class="slider">
<div class="slider-wrapper">
<div class="slide">
<div class="slide-content">
<h2>Projet 1</h2>
<p>Site web d'entreprise</p>
</div>
</div>
<div class="slide">
<div class="slide-content">
<h2>Projet 2</h2>
<p>Application mobile</p>
</div>
</div>
<div class="slide">
<div class="slide-content">
<h2>Projet 3</h2>
<p>E-commerce</p>
</div>
</div>
<div class="slide">
<div class="slide-content">
<h2>Projet 4</h2>
<p>Tableau de bord analytique</p>
</div>
</div>
</div>
<div class="slider-indicators">
<div class="indicator"></div>
<div class="indicator"></div>
<div class="indicator"></div>
<div class="indicator"></div>
</div>
</div>
<!-- Galerie de projets -->
<section class="gallery" id="projects">
<h2 class="gallery-title">Mes projets</h2>
<div class="projects-grid">
<div class="project-card">
<div class="project-image">
<div class="project-wave"></div>
</div>
<div class="project-content">
<h3 class="project-title">Projet Alpha</h3>
<p class="project-description">Une application web moderne utilisant les dernières technologies.</p>
</div>
</div>
<div class="project-card">
<div class="project-image">
<div class="project-wave"></div>
</div>
<div class="project-content">
<h3 class="project-title">Projet Beta</h3>
<p class="project-description">Une boutique en ligne responsive avec un système de paiement avancé.</p>
</div>
</div>
<div class="project-card">
<div class="project-image">
<div class="project-wave"></div>
</div>
<div class="project-content">
<h3 class="project-title">Projet Gamma</h3>
<p class="project-description">Un système de gestion de contenu pour les grandes entreprises.</p>
</div>
</div>
<div class="project-card">
<div class="project-image">
<div class="project-wave"></div>
</div>
<div class="project-content">
<h3 class="project-title">Projet Delta</h3>
<p class="project-description">Une plateforme éducative interactive avec gamification.</p>
</div>
</div>
<div class="project-card">
<div class="project-image">
<div class="project-wave"></div>
</div>
<div class="project-content">
<h3 class="project-title">Projet Epsilon</h3>
<p class="project-description">Une application mobile pour la gestion des finances personnelles.</p>
</div>
</div>
<div class="project-card">
<div class="project-image">
<div class="project-wave"></div>
</div>
<div class="project-content">
<h3 class="project-title">Projet Zeta</h3>
<p class="project-description">Un portail social pour les passionnés de photographie.</p>
</div>
</div>
</div>
</section>
<!-- Section des compétences -->
<section class="skills" id="skills">
<h2 class="skills-title">Compétences</h2>
<div class="skill-item">
<div class="skill-name">HTML/CSS</div>
<div class="skill-bar">
<div class="skill-progress"></div>
</div>
</div>
<div class="skill-item">
<div class="skill-name">JavaScript</div>
<div class="skill-bar">
<div class="skill-progress"></div>
</div>
</div>
<div class="skill-item">
<div class="skill-name">Animations CSS</div>
<div class="skill-bar">
<div class="skill-progress"></div>
</div>
</div>
<div class="skill-item">
<div class="skill-name">Responsive Design</div>
<div class="skill-bar">
<div class="skill-progress"></div>
</div>
</div>
</section>
<!-- Pied de page -->
<footer class="footer">
<p>© 2024 Portfolio 3D. Tous droits réservés.</p>
</footer>
</body>
</html>Récapitulatif
Ce projet illustre des techniques d'animation CSS avancées sans utiliser JavaScript :
- @keyframes - 17 animations différentes
- animation-timing-function - différentes fonctions de timing (linear, ease, ease-in-out)
- animation-delay - animations séquentielles avec des délais précis
- animation-direction - sens d'animation normal et inversé
- animation-iteration-count - animations uniques et infinies
- animation-fill-mode - forwards et backwards pour préserver les états
- Transform 3D - un cube 3D complet dans l'espace preserve-3d
- Diaporama automatique - en utilisant uniquement CSS
- Indicateurs de progression animés - synchronisation de plusieurs animations
- Effets de particules - éléments animés disposés de façon à paraître aléatoires
Le projet est entièrement responsive et utilise les techniques CSS les plus récentes pour créer une présentation de portfolio impressionnante sans une seule ligne de JavaScript. Mon conseil : ajoute la règle prefers-reduced-motion du lieu précédent, car une partie des visiteurs désactive les animations dans leur système.
Dans l'éditeur ci-dessous, tu vas t'exercer à ces techniques sur une scène plus petite, avec le couvercle d'un sarcophage. Le parent .tomb a déjà perspective: 500px, et le couvercle transform-origin: top center, il suffit donc de décommenter l'animation openLid et ses @keyframes.
Code de cette leçon : style.css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', sans-serif;
background: linear-gradient(180deg, #1a0a2e, #3d2914);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
color: white;
}
.scene {
text-align: center;
padding: 20px;
}
h2 {
margin-bottom: 30px;
color: #f0c040;
}
.tomb {
display: flex;
justify-content: center;
perspective: 500px;
}
.sarcophagus {
position: relative;
width: 200px;
height: 300px;
}
.base {
width: 200px;
height: 280px;
background: linear-gradient(180deg, #d4af37, #b8941e);
border-radius: 10px 10px 5px 5px;
display: flex;
align-items: center;
justify-content: center;
font-size: 40px;
border: 3px solid #8d6e2e;
position: absolute;
bottom: 0;
}
.lid {
width: 210px;
height: 50px;
background: linear-gradient(180deg, #c9a84c, #a88932);
border-radius: 8px 8px 0 0;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
font-weight: bold;
border: 3px solid #8d6e2e;
position: absolute;
top: 0;
left: -5px;
transform-origin: top center;
/* Ajoute la syntaxe raccourcie animation ici */
/* animation: openLid 3s ease-in-out 1s 1 normal forwards; */
}
/* Définis @keyframes openLid */
/* @keyframes openLid { */
/* 0% { transform: rotateX(0deg); } */
/* 100% { transform: rotateX(-120deg); } */
/* } */
.hint {
margin-top: 30px;
color: #aaa;
font-style: italic;
}Souviens-toi : une galerie 3D est une chambre funéraire où la perspective place le spectateur, où les images clés racontent l'histoire et où les délais la dévoilent image après image.
Entrées de la documentation utilisées dans cette leçon
Tu as repéré une erreur dans cette leçon ?
Teste tes connaissances
Réponds aux questions de cette leçon. Choisis une réponse pour voir tout de suite si elle est correcte.
1. Quelle propriété CSS, appliquée au parent, crée une scène 3D avec de la profondeur pour ses éléments enfants ?
2. Quelle fonction transform fait pivoter un carrousel 3D autour de l'axe vertical ?
Voici 2 des 3 questions de cette leçon. Réponds aux autres dans le jeu.
Tâches pratiques dans le jeu
- Tri vertical
Classe les étapes de construction de la galerie 3D animée, des fondations jusqu'à l'effet final :