JSFiddle - React, Tailwind, and code Playground
HTML
<div class="wrapper">
<button class="btn btn-call-header">Заказать звонок</button>
<button class="btn btn-call">Заказать звонок</button>
</div>
<div class="modal call-back">
<div class="close">✕</div>
<div class="name">Заказать звонок</div>
Закажите звонок и наши специалисты обязательно с вами свяжутся
<input type="text" placeholder="Контактное лицо">
<input type="tel" placeholder="Телефон">
<button type="submit" class="btn btn-modal-call">Заказать звонок</button>
</div>
<div class="modal news-back">
<div class="close">✕</div>
<div class="name">Хотите узнавать новости первым?</div>
<input type="text" placeholder="Контактное лицо">
<input type="tel" placeholder="Телефон">
<button type="submit" class="btn btn-modal-call">Подписаться</button>
</div>
CSS
html, body{height:100%}
.wrapper {
display: flex;
flex-direction: column;
justify-content: space-between;
background: lightyellow;
height:90%;
padding: 10px;
}
.btn {
display: block;
}
.modal {
display: none;
position: fixed;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 30%;
height: auto;
box-shadow: 0 0 0 99999px rgba(60, 55, 54, 0.75);
text-align: center;
padding: 40px;
font-size: 16px;
z-index: 100;
}
.modal:not(:focus) {
display: none;
}
.modal input {
height: 46px;
line-height: 46px;
width: 100%;
padding: 0 10px;
border: none;
font-size: 16px;
}
.modal input:first-of-type {
margin: 30px 0 0;
}
.modal input:last-of-type {
margin: 20px 0 30px;
}
.close {
float: right;
position: relative;
right: -130px;
top: -78px;
color: #fff;
cursor: pointer;
font-size: 26px;
font-weight: 700;
}
JavaScript
/***** toggle modals *****/
$(".btn-call-header, .btn-call").click(
function () {
$(".call-back").slideToggle("fast");
});
$(".btn-subscribe").click(
function () {
$(".news-back").slideToggle("fast");
});
$(".close").click(
function () {
$(".modal").css("display", "none");
});
//закрытие окна по ESC
$(document).keydown(function (e) {
if ($(".modal").is(":visible") && (e.which == 27 || e.keyCode == 27)) {
$(".modal").hide();
}
});