Wie erstellt man: Pop-up-Fenster
- Previous page Hover to display element
- Next page Collapsible content
Lernen Sie, wie man mit CSS und JavaScript Pop-up-Fenster erstellt.
Klicken Sie auf mich, um das Anzeigen des Pop-ups zu wechseln!
Ein einfaches Pop-up-Fenster!
Wie erstellt man ein Pop-up-Fenster?
Schritt 1 - Fügen Sie HTML hinzu:
<div class="popup" onclick="myFunction()">Click me!</div> <span class="popuptext" id="myPopup">Popup text...</span> </div>
Zweiter Schritt - Fügen Sie CSS hinzu:
/* Pop-up-Container */ .popup { position: relative; display: inline-block; cursor: pointer; } /* Tatsächliches Pop-up (erscheint oben) */ .popup .popuptext { visibility: hidden; width: 160px; background-color: #555; color: #fff; text-align: center; border-radius: 6px; padding: 8px 0; position: absolute; z-index: 1; bottom: 125%; left: 50%; margin-left: -80px; } /* Pfeil des Pop-ups */ .popup .popuptext::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border-width: 5px; border-style: solid; border-color: #555 transparent transparent transparent; } /* Ändern Sie diese Klasse, wenn auf den Pop-up-Container geklickt wird (Verbergen und Anzeigen des Pop-ups) */ .popup .show { visibility: visible; -webkit-animation: fadeIn 1s; animation: fadeIn 1s } /* Fügen Sie Animationen hinzu (Pop-up-Fenster einblenden) */ @-webkit-keyframes fadeIn { from {opacity: 0;} to {opacity: 1;} } @keyframes fadeIn { from {opacity: 0;} to {opacity:1 ;} }
Dritter Schritt - Fügen Sie JavaScript hinzu:
<script> // Wenn der Benutzer auf <div> klickt, öffnet sich das Pop-up-Fenster function myFunction() { var popup = document.getElementById("myPopup"); popup.classList.toggle("show"); } </script>
Related pages
Tutorial:CSS tooltip
Tutorial:How to create modal
- Previous page Hover to display element
- Next page Collapsible content