Pure CSS Modal
How do I make an pure css modal?
This is just a simple demo of a simple, pure CSS modal window that is addressable via URL fragment.The JS enhancement returns focus to the triggering link.. What is a pure css modal? How do you make a pure css modal? This script and codes were developed by Aaron Gustafson on 13 August 2022, Saturday.
Pure CSS Modal - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Pure CSS Modal</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <p><a href="#modal-message">Create a new message</a></p>
<div id="modal-message" class="modal"> <div class="modal__window"> <h2 class="modal__title">New Message</h2> <form action=""> <p> <label for="test">Label</label> <input type="text" id="test"> </p> <p><button>Submit</button></p> </form> </div> <a class="modal__closer" href="#">Close</a>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Pure CSS Modal - Script Codes CSS Codes
body { padding: 1em;
}
.modal { background: rgba(0, 0, 0, 0.5); /* Internet Explorer 10 */ display: -ms-flexbox; -ms-flex-pack: center; -ms-flex-align: center; /* Firefox */ display: -moz-box; -moz-box-pack: center; -moz-box-align: center; /* Safari, Opera, and Chrome */ display: -webkit-box; -webkit-box-pack: center; -webkit-box-align: center; /* W3C */ display: box; box-pack: center; box-align: center; position: absolute; top: 0; left: 100%; right: 0; bottom: 0; -moz-transition: opacity .25s linear, left 0 .25s; -ms-transition: opacity .25s linear, left 0 .25s; -webkit-transition: opacity .25s linear, left 0 .25s; transition: opacity .25s linear, left 0 .25s; left: 100%; opacity: 0.0001;
}
.modal:target { left: 0; opacity: 1; -moz-transition: opacity .25s linear; -ms-transition: opacity .25s linear; -webkit-transition: opacity .25s linear; transition: opacity .25s linear;
}
.modal:focus { outline-width: 0;
}
.modal__window { background: #fff; border: 1px solid; box-shadow: 1px 1px 1px #000; padding: 20px; width: 200px; position: relative; z-index: 1;
}
.modal:focus .modal__window { outline-color: #5B9DD9; outline-offset: 0px; outline-style: auto; outline-width: 5px;
}
.modal__title { background: #ebebeb; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; margin: -20px -20px 10px; padding: 10px 20px; border-bottom: 1px solid;
}
.modal__closer { white-space: nowrap; overflow: hidden; text-indent: 100%; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
}
Pure CSS Modal - Script Codes JS Codes
(function(){ function assignCloserTarget() { var target = document.querySelector( this.href.replace( re_hash, '$1' ) ), closer = target.querySelector('.modal__closer'); // Add the event listener if we have not touched the node before if ( closer.returnTo == undefined ) { closer.addEventListener( 'click', returnToLink ); } closer.returnTo = this; target.focus(); } function returnToLink( e ) { if ( this.returnTo != undefined ) { this.returnTo.focus(); } } var forEach = Array.prototype.forEach, modal_links = document.querySelectorAll('a[href^="#modal"]'), modals = document.querySelectorAll('.modal'), re_hash = /^.*?(#.*)$/; forEach.call( modal_links, function( link ){ link.addEventListener( 'click', assignCloserTarget ); }); forEach.call( modals, function( modal ){ modal.setAttribute('tabindex','-1'); });
}());
Developer | Aaron Gustafson |
Username | aarongustafson |
Uploaded | August 13, 2022 |
Rating | 3 |
Size | 3,569 Kb |
Views | 26,312 |
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!
Name | Size |
Un-doing tables | 3,993 Kb |
Simple Compact Labels | 1,978 Kb |
Lazy Loading Images | 4,245 Kb |
Form Patterns | 5,922 Kb |
Simple pull quote | 3,392 Kb |
Simplified JS-based MQ Inspector | 2,353 Kb |
Easy Couch Mode | 8,819 Kb |
Footnote references that maintain good user focus | 2,167 Kb |
Visualizing CSS Transforms | 3,155 Kb |
FAQ JS-Enhanced Tab Order | 3,573 Kb |
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!
Name | Username | Size |
STIKHOI | Denmch | 7,122 Kb |
Login-ng-modal | Heedoo | 3,566 Kb |
Sass Get Function | Lukewatts | 2,155 Kb |
Addthis_button | Esambino | 1,691 Kb |
Parallax with only CSS | Thulioph | 2,297 Kb |
Find The Penguin | Lelder | 2,212 Kb |
Animated Donut Chart | Jplhomer | 3,808 Kb |
Base64 SVG Me | MrBambule | 44,786 Kb |
Animated bar chart | CreativePunch | 3,124 Kb |
Pomodoro Clock | Osycon | 3,705 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!