Pure CSS modal box

Size
3,364 Kb
Views
18,216

How do I make an pure css modal box?

I'm using labels as a triggers for checkbox which state indicates visibility of modal box.. What is a pure css modal box? How do you make a pure css modal box? This script and codes were developed by Kasper Mikiewicz on 21 November 2022, Monday.

Pure CSS modal box Previews

Pure CSS modal box - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Pure CSS modal box</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ /* [Object] Modal * =============================== */
.modal { opacity: 0; visibility: hidden; position: fixed; top: 0; right: 0; bottom: 0; left: 0; text-align: left; background: rgba(0,0,0, .9); transition: opacity .25s ease;
}
.modal__bg { position: absolute; top: 0; right: 0; bottom: 0; left: 0; cursor: pointer;
}
.modal-state { display: none;
}
.modal-state:checked + .modal { opacity: 1; visibility: visible;
}
.modal-state:checked + .modal .modal__inner { top: 0;
}
.modal__inner { transition: top .25s ease; position: absolute; top: -20%; right: 0; bottom: 0; left: 0; width: 50%; margin: auto; overflow: auto; background: #fff; border-radius: 5px; padding: 1em 2em; height: 50%;
}
.modal__close { position: absolute; right: 1em; top: 1em; width: 1.1em; height: 1.1em; cursor: pointer;
}
.modal__close:after,
.modal__close:before { content: ''; position: absolute; width: 2px; height: 1.5em; background: #ccc; display: block; transform: rotate(45deg); left: 50%; margin: -3px 0 0 -1px; top: 0;
}
.modal__close:hover:after,
.modal__close:hover:before { background: #aaa;
}
.modal__close:before { transform: rotate(-45deg);
}
@media screen and (max-width: 768px) { .modal__inner { width: 90%; height: 90%; box-sizing: border-box; }
}
/* Other * =============================== */
body { padding: 1%; font: 1/1.5em sans-serif; text-align: center;
}
.btn { cursor: pointer; background: #27ae60; display: inline-block; padding: .5em 1em; color: #fff; border-radius: 3px;
}
.btn:hover,
.btn:focus { background: #2ecc71;
}
.btn:active { background: #27ae60; box-shadow: 0 1px 2px rgba(0,0,0, .2) inset;
}
.btn--blue { background: #2980b9;
}
.btn--blue:hover,
.btn--blue:focus { background: #3498db;
}
.btn--blue:active { background: #2980b9;
}
p img { max-width: 200px; height: auto; float: left; margin: 0 1em 1em 0;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <h1>Pure CSS modal box</h1>
<div> <p>You can place trigger button wherever you want.</p> <p> <label class="btn" for="modal-1">Show me modal with a cat</label> <label class="btn btn--blue" for="modal-2">Click for more AWW</label> </p>
</div>
<input class="modal-state" id="modal-1" type="checkbox" />
<div class="modal"> <label class="modal__bg" for="modal-1"></label> <div class="modal__inner"> <label class="modal__close" for="modal-1"></label> <h2>Caaaats FTW!</h2> <p><img src="https://i.imgur.com/HnrkBwB.gif" alt="" />Aliquam in sagittis nulla. Curabitur euismod diam eget risus venenatis, sed dictum lectus bibendum. Nunc nunc nisi, hendrerit eget nisi id, rhoncus rutrum velit. Nunc vel mauris dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aliquam fringilla quis nisi eget imperdiet.</p> </div>
</div>
<input class="modal-state" id="modal-2" type="checkbox" />
<div class="modal"> <label class="modal__bg" for="modal-2"></label> <div class="modal__inner"> <label class="modal__close" for="modal-2"></label> <h2>Sleppy sloth</h2> <p><img src="https://i.imgur.com/TPx9zYo.gif" alt="" />Aliquam in sagittis nulla. Curabitur euismod diam eget risus venenatis, sed dictum lectus bibendum. Nunc nunc nisi, hendrerit eget nisi id, rhoncus rutrum velit. Nunc vel mauris dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aliquam fringilla quis nisi eget imperdiet.</p> </div>
</div>
</body>
</html>

Pure CSS modal box - Script Codes CSS Codes

/* [Object] Modal * =============================== */
.modal { opacity: 0; visibility: hidden; position: fixed; top: 0; right: 0; bottom: 0; left: 0; text-align: left; background: rgba(0,0,0, .9); transition: opacity .25s ease;
}
.modal__bg { position: absolute; top: 0; right: 0; bottom: 0; left: 0; cursor: pointer;
}
.modal-state { display: none;
}
.modal-state:checked + .modal { opacity: 1; visibility: visible;
}
.modal-state:checked + .modal .modal__inner { top: 0;
}
.modal__inner { transition: top .25s ease; position: absolute; top: -20%; right: 0; bottom: 0; left: 0; width: 50%; margin: auto; overflow: auto; background: #fff; border-radius: 5px; padding: 1em 2em; height: 50%;
}
.modal__close { position: absolute; right: 1em; top: 1em; width: 1.1em; height: 1.1em; cursor: pointer;
}
.modal__close:after,
.modal__close:before { content: ''; position: absolute; width: 2px; height: 1.5em; background: #ccc; display: block; transform: rotate(45deg); left: 50%; margin: -3px 0 0 -1px; top: 0;
}
.modal__close:hover:after,
.modal__close:hover:before { background: #aaa;
}
.modal__close:before { transform: rotate(-45deg);
}
@media screen and (max-width: 768px) { .modal__inner { width: 90%; height: 90%; box-sizing: border-box; }
}
/* Other * =============================== */
body { padding: 1%; font: 1/1.5em sans-serif; text-align: center;
}
.btn { cursor: pointer; background: #27ae60; display: inline-block; padding: .5em 1em; color: #fff; border-radius: 3px;
}
.btn:hover,
.btn:focus { background: #2ecc71;
}
.btn:active { background: #27ae60; box-shadow: 0 1px 2px rgba(0,0,0, .2) inset;
}
.btn--blue { background: #2980b9;
}
.btn--blue:hover,
.btn--blue:focus { background: #3498db;
}
.btn--blue:active { background: #2980b9;
}
p img { max-width: 200px; height: auto; float: left; margin: 0 1em 1em 0;
}
Pure CSS modal box - Script Codes
Pure CSS modal box - Script Codes
Home Page Home
Developer Kasper Mikiewicz
Username Idered
Uploaded November 21, 2022
Rating 4
Size 3,364 Kb
Views 18,216
Do you need developer help for Pure CSS modal box?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Kasper Mikiewicz (Idered) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!