No JS Modals

2,843 Kb

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 Previews

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">
<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">&times;</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 class="modal bg--blue" role="dialog" id="modalB" aria-labelledby="modalB-title" aria-describedby="modalB-description">	<a href="#" class="modal-exit" title="close">&times;</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 class="modal bg--red" role="dialog" id="modalC" aria-labelledby="modalC-title" aria-describedby="modalC-description">	<a href="#" class="modal-exit" title="close">&times;</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 class="modal bg--green" role="dialog" id="modalD" aria-labelledby="modalD-title" aria-describedby="modalD-description">	<a href="#" class="modal-exit" title="close">&times;</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 class="modal bg--purple" role="dialog" id="modalE" aria-labelledby="modalE-title" aria-describedby="modalE-description">	<a href="#" class="modal-exit" title="close">&times;</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>
<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>

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
No JS Modals - Script Codes
No JS Modals - Script Codes
Home Page Home
Developer Zachary Olson
Username zacharyolson
Uploaded November 10, 2022
Rating 4.5
Size 2,843 Kb
Views 18,216
Do you need developer help for No JS Modals?

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!

Zachary Olson (zacharyolson) Script Codes
Create amazing blog posts 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!