Exécuter
❯
Exécuter le code
Ctrl+Alt+R
Enregistrer le code
Ctrl+Alt+A
Changer d'orientation
Ctrl+Alt+O
Changer de thème
Ctrl+Alt+D
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> * { marge: 0; padding: 0; box-sizing: border-box; } h1 { text-align: center; padding: 20px; } .gallery { afficher: flex; flex-wrap: wrap; justify-content: flex-start; padding: 0 15px; } .gallery-item { position: relative; largeur: calc(25% - 20px); hauteur: auto; marge: 10px; curseur: pointeur; transition: transform 0.5s ease; } .gallery-item:hover { transform: scale(1.1); } /* La Modale (arrière-plan) */ .modal { afficher: aucun; position: fixe; z-index: 1000; gauche: 0; haut: 0; largeur: 100%; hauteur: 100%; couleur-de-fond: rgba(0, 0, 0, 0.8); align-items: center; justify-content: center; transition: opacity 0.5s ease; } /* Contenu modal (image) */ .modal-content { position: relative; largeur: 90%; hauteur: auto; max-width: 90%; max-height: 90%; border-radius: 5px; débordement: caché; animation: zoomIn 0.5s; } @keyframes zoomIn { from {transform: scale(0.6);} à {transform: scale(1);} } .modal.show { afficher: flex; opacité: 1; } /* Bouton de fermeture */ .close { position: absolute; haut: 10px; droite: 15px; couleur: #ffffff; taille-de-police: 35px; font-weight: bold; curseur: pointeur; transition: transform 0.3s; } /* Légende de l'image modale */ .caption { position: absolute; bas: 15px; largeur: 100%; text-align: center; couleur: #ffffff; taille de police: 24px; } @media screen and (max-width: 768px) { .gallery-item { largeur: calc(50% - 20px); } } @media screen and (max-width: 480px) { .gallery-item { largeur: calc(100% - 20px); } } </style> </head> <body> <h1>Images modales réactives</h1> <div class="gallery"> <img src="img_5terre.jpg" alt="Cinque Terre" class="gallery-item" onclick="openModal('modal1', 'Cinque Terre')" width="600" height="400"> <img src="img_forest.jpg" alt="Forest" class="gallery-item" onclick="openModal('modal2', 'Forest')" width="600" height="400"> <img src="img_lights.jpg" alt="Northern Lights" class="gallery-item" onclick="openModal('modal3', 'Nothern Lights')" width="600" height="400"> <img src="img_mountains.jpg" alt="Mountains" class="gallery-item" onclick="openModal('modal4', 'Mountains')" width="600" height="400"> </div> <div id="modal1" class="modal"> <span class="close" onclick="closeModal('modal1')">×</span> <img src="img_5terre.jpg" alt="Cinque Terre" class="modal-content" width="600" height="400"> <div class="caption"></div> </div> <div id="modal2" class="modal"> <span class="close" onclick="closeModal('modal2')">×</span> <img src="img_forest.jpg" alt="Forest" class="modal-content" width="600" height="400"> <div class="caption"></div> </div> <div id="modal3" class="modal"> <span class="close" onclick="closeModal('modal3')">×</span> <img src="img_lights.jpg" alt="Northern Lights" class="modal-content" width="600" height="400"> <div class="caption"></div> </div> <div id="modal4" class="modal"> <span class="close" onclick="closeModal('modal4')">×</span> <img src="img_mountains.jpg" alt="Mountains" class="modal-content" width="600" height="400"> <div class="caption"></div> </div> <script> function openModal(modalId, caption) { let modal = document.getElementById(modalId); modal.style.display = "flex"; modal.classList.add("show"); let message = modal.querySelector(".caption"); message.innerText = légende; } function closeModal(modalId) { let modal = document.getElementById(modalId); modal.classList.remove("show"); setTimeout(function () { modal.style.display = "none"; modal.querySelector(".caption").innerText = ""; }, 300); } </script> </body> </html>