Now you can add pop-ups or modal lightbox with CSS only (and really minor single line of JavaScript) on your html, wordpress or bootstrap website, so don’t be afraid.
DEMO: CSS Modal Lightbox
HTML
Copy the code below and paste into your HTML document.
<button onclick="document.getElementById('modal-1').style.display='block'">Click Here</button> <div id="modal-1" class="modal animate-opacity"> <div class="modal-content"> <div class="modal-inner"> <span onclick="document.getElementById('modal-1').style.display='none'" class="modal-close">×</span> <h4>Modal Headline</h4> <p>Modal description goes here.</p> </div> </div> </div>
You can add multiple modals. Copy the entire codes and replace all modal-1
into modal-2
and modal-3
…
CSS
Copy the code below and paste into your CSS document.
.modal { z-index: 10; display: none; padding-top: 100px; position: fixed; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.5) } .modal-content { margin: auto; background-color: #fff; position: relative; padding: 0; outline: 0; max-width: 600px } .modal-inner { padding: 20px 30px; } .modal-close { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; position: absolute; right: 0; top: 0; background: #ccc; padding: 6px 10px; } .animate-opacity { animation: opac 0.8s }@keyframes opac{from{opacity:0} to{opacity:1}}
These 4 classes would do the job, and the last class, .animate-opacity
is the animated effect when modal opens (so it’s optional).
You can tweak the animation time slower or faster by changing the speed time. It’s currently 0.8 seconds, opac 0.8s
, but change it as you need it. Have fun!