No JS Modals
How do I make an no js modals?
Not sure where I first saw this, but it's my favorite way to do simple modals. Requires no JS and even adds browser history so that back button works. Adding modal transitions is pretty easy too. . What is a no js modals? How do you make a no js modals? This script and codes were developed by Zachary Olson on 10 November 2022, Thursday.
No JS Modals - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>No JS Modals</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <section class="modal bg--purple" role="dialog" id="modalA" aria-labelledby="modalA-title" aria-describedby="modalA-description"> <a href="#" class="modal-exit" title="close">×</a> <h1 id="modalA-title" class="modal-title">Modal A</h1> <p id="modalA-description" class="modal-description">Lots of fun things in here to see.</p>
</section>
<section class="modal bg--blue" role="dialog" id="modalB" aria-labelledby="modalB-title" aria-describedby="modalB-description"> <a href="#" class="modal-exit" title="close">×</a> <h1 id="modalB-title" class="modal-title">Modal B</h1> <p id="modalB-description" class="modal-description">Lots of fun things in here to see.</p>
</section>
<section class="modal bg--red" role="dialog" id="modalC" aria-labelledby="modalC-title" aria-describedby="modalC-description"> <a href="#" class="modal-exit" title="close">×</a> <h1 id="modalC-title" class="modal-title">Modal C</h1> <p id="modalC-description" class="modal-description">Lots of fun things in here to see.</p>
</section>
<section class="modal bg--green" role="dialog" id="modalD" aria-labelledby="modalD-title" aria-describedby="modalD-description"> <a href="#" class="modal-exit" title="close">×</a> <h1 id="modalD-title" class="modal-title">Modal D</h1> <p id="modalD-description" class="modal-description">Lots of fun things in here to see.</p>
</section>
<section class="modal bg--purple" role="dialog" id="modalE" aria-labelledby="modalE-title" aria-describedby="modalE-description"> <a href="#" class="modal-exit" title="close">×</a> <h1 id="modalE-title" class="modal-title">Modal E</h1> <p id="modalE-description" class="modal-description">Lots of fun things in here to see.</p>
</section>
<main class="content"> <a href="#modalA" class="modal-open"> View Modal A </a> <a href="#modalB" class="modal-open"> View Modal B </a> <a href="#modalC" class="modal-open"> View Modal C </a> <a href="#modalD" class="modal-open"> View Modal D </a> <a href="#modalE" class="modal-open"> View Modal E </a>
</main> <script src="js/index.js"></script>
</body>
</html>
No JS Modals - Script Codes CSS Codes
/*
The main content is inside of our element.
Make it fill the whole window and be scrollable - body should not scroll.
*/
body { margin: 0; padding: 0; overflow: hidden;
}
.content { position: fixed; top: 0; left: 0; bottom: 0; right: 0; overflow: scroll;
}
/*
Modals should cover the whole screen, but be hidden by default.
When we click a link to #ModalName, #ModalName becomes the :target element and we can use this selector to give it new styles, like display:block;
Notice our "Close" links have an href of "#", which means none of our modals are now the :target. They will now all fall back to the basicl .modal styling.
*/
.modal { position: absolute; top: 0; left: 0; bottom: 0; right: 0; display: none; opacity: 0; overflow: scroll;
}
.modal:target { display: block; z-index: 2; opacity: 1;
}
.popup:target ~ .content { overflow: hidden;
}
/* ---------------------------- Styling just for funsies. You can ignore this. ------------------------------- */
body { font-family: helvetica, arial, sans-serif; font-weight: 100; text-align: center; color: #FFF;
}
.content { background-color: #EDEBEE;
}
.modal-exit,
.modal-exit:hover { position: fixed; top: 0; right: 0; width: 1em; height: 1em; z-index: 10; padding: 0.3em; font-size: 2em; line-height: 1em; text-decoration: none; color: #FFF;
}
.modal-exit:hover { background-color: rgba(255,255,255, 0.3);
}
.modal-open,
.modal-open:hover { display: block; width: 10em; margin: 1em auto; padding: 2em 1em; border: 1px solid #806973; background-color: #FFF; font-size: 2em; text-align: center; text-decoration: none; color: #806973; box-shadow: 0 0 10px 1px #CCC;
}
.modal-open:hover { box-shadow: 0 0 10px 1px #999;
}
.modal-title { font-size: 3em; font-weight: 100;
}
.modal-description { padding: 1em; font-size: 1.2em; letter-spacing: 0.1em; color: #EDEBEE;
}
.bg--purple { background-color: #806973;
}
.bg--blue { background-color: #696E80;
}
.bg--red { background-color: #806969;
}
.bg--green { background-color: #69807D;
}
No JS Modals - Script Codes JS Codes
/* No JS Modals
*/

Developer | Zachary Olson |
Username | zacharyolson |
Uploaded | November 10, 2022 |
Rating | 4.5 |
Size | 2,843 Kb |
Views | 18,207 |
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 |
D3 version of animated chart dribbble | 4,327 Kb |
Nerdventure Feed | 4,817 Kb |
Blackberry Mock | 1,865 Kb |
Convert JSON to ruby hash | 2,000 Kb |
Hovers with popups | 2,380 Kb |
Border Radius Bouncer | 2,415 Kb |
Css version of macbook dribbble | 2,919 Kb |
Scroll Position Indicators | 5,711 Kb |
A Pen by Zachary Olson | 1,163 Kb |
IMac Mock | 2,046 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 |
Part 19 Bootstrap split button dropdown | Venkatesha | 1,601 Kb |
Button fills | Zubfatal | 5,205 Kb |
Free css icon set v2 - one div | Ben_jammin | 0 Kb |
Resize image | Happyhj | 1,892 Kb |
Coming Soon | MariamMassadeh | 1,680 Kb |
Flex layout example | Mofny | 1,663 Kb |
Elephants Full screen site | Orrinward | 3,981 Kb |
Resizable SASS Icons | Marianarlt | 7,611 Kb |
Kut D3 | Jellevrswk | 3,687 Kb |
WRENCH - STAFF | Lolita-adams | 1,608 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!