Responsive Modal

Developer
Size
4,178 Kb
Views
6,072

How do I make an responsive modal?

What is a responsive modal? How do you make a responsive modal? This script and codes were developed by Daniel Grant on 28 December 2022, Wednesday.

Responsive Modal Previews

Responsive Modal - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Responsive Modal</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! */ * { position: relative; box-sizing: border-box;
}
html, body { height: 100%; overflow: hidden;
}
.cf:before, .Modal-header:before,
.cf:after,
.Modal-header:after { content: " "; display: table;
}
.cf:after, .Modal-header:after { clear: both;
}
.Modal { position: absolute; width: 100%; height: 100%; z-index: 100; background: #fff; backface-visibility: hidden;
}
.Modal-header { background: #fff; border-bottom: 1px solid #ccc;
}
.Modal-header h3 { position: absolute; width: 100%; line-height: 32px; text-align: center;
}
.Modal-body { height: 100%; background: #eee;
}
.Modal-footer { border-top: 1px solid #ccc;
}
@media screen and (max-width: 599px) { .tablet { display: none; } .Modal { transition: transform 0.35s linear; transform: translateY(200%); } .Modal.is-open { transform: translateY(0%); }
}
@media screen and (min-width: 600px) { .mobile { display: none; } .tablet { display: block; } .Modal { position: absolute; left: 50%; top: 50%; transform: translate(-50%, 75%); opacity: 0; width: 500px; height: auto; } .Modal.is-open { transform: translate(-50%, -50%); box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.7); opacity: 1; transition: transform 0.2s linear 0.2s, opacity 0.4s linear; } .Modal.is-closed { opacity: 0; transition: opacity 1s linear, transform 0.2s linear; } .Modal-header h3 { position: relative; } .Modal-body { height: 250px; }
}
h1, h2, h3 { line-height: 1; margin: 0;
}
button { padding: 0 8px; border: none; border-radius: 3px; background: #ccc; color: #444; transition: 0.1s; height: 30px; line-height: 30px;
}
button:active { background: #ddd; box-shadow: inset 1px 2px rgba(0, 0, 0, 0.1);
}
.gutter { padding: 12px;
}
.muted { color: #999;
}
.pull-left { float: left;
}
.pull-right { float: right;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div class="Modal is-closed" id="modal"> <div class="Modal-header gutter mobile"> <h3>Send Email</h3> <button data-hook="button-cancel" class="pull-left">Cancel</button> <button data-hook="button-send" class="pull-right">Send</button> </div> <div class="Modal-header gutter tablet"> <h3>Send Email</h3> </div> <div class="Modal-body gutter"> <p class="muted">Start typing...</p> </div> <div class="Modal-footer gutter tablet"> <button data-hook="button-cancel">Cancel</button> <button data-hook="button-send" class="pull-right">Send</button> </div>
</div>
<div class="gutter"> <button data-hook="button-open">Compose</button>
</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>

Responsive Modal - Script Codes CSS Codes

* { position: relative; box-sizing: border-box;
}
html, body { height: 100%; overflow: hidden;
}
.cf:before, .Modal-header:before,
.cf:after,
.Modal-header:after { content: " "; display: table;
}
.cf:after, .Modal-header:after { clear: both;
}
.Modal { position: absolute; width: 100%; height: 100%; z-index: 100; background: #fff; backface-visibility: hidden;
}
.Modal-header { background: #fff; border-bottom: 1px solid #ccc;
}
.Modal-header h3 { position: absolute; width: 100%; line-height: 32px; text-align: center;
}
.Modal-body { height: 100%; background: #eee;
}
.Modal-footer { border-top: 1px solid #ccc;
}
@media screen and (max-width: 599px) { .tablet { display: none; } .Modal { transition: transform 0.35s linear; transform: translateY(200%); } .Modal.is-open { transform: translateY(0%); }
}
@media screen and (min-width: 600px) { .mobile { display: none; } .tablet { display: block; } .Modal { position: absolute; left: 50%; top: 50%; transform: translate(-50%, 75%); opacity: 0; width: 500px; height: auto; } .Modal.is-open { transform: translate(-50%, -50%); box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.7); opacity: 1; transition: transform 0.2s linear 0.2s, opacity 0.4s linear; } .Modal.is-closed { opacity: 0; transition: opacity 1s linear, transform 0.2s linear; } .Modal-header h3 { position: relative; } .Modal-body { height: 250px; }
}
h1, h2, h3 { line-height: 1; margin: 0;
}
button { padding: 0 8px; border: none; border-radius: 3px; background: #ccc; color: #444; transition: 0.1s; height: 30px; line-height: 30px;
}
button:active { background: #ddd; box-shadow: inset 1px 2px rgba(0, 0, 0, 0.1);
}
.gutter { padding: 12px;
}
.muted { color: #999;
}
.pull-left { float: left;
}
.pull-right { float: right;
}

Responsive Modal - Script Codes JS Codes

$btns = $("[data-hook='button-open'], [data-hook='button-cancel'], [data-hook='button-send']");
$modal = $('#modal');
$btns.on('click', function() { $modal.toggleClass('is-open').toggleClass('is-closed');
});
Responsive Modal - Script Codes
Responsive Modal - Script Codes
Home Page Home
Developer Daniel Grant
Username djgrant
Uploaded December 28, 2022
Rating 3
Size 4,178 Kb
Views 6,072
Do you need developer help for Responsive Modal?

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!

Daniel Grant (djgrant) 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!