0

У меня почему-то псевдо класс :after у блока .modal перекрывает всё содержимое на странице

document.getElementById("close").onclick = function() {
  document.getElementById("myModal").style.display = "none";
};

document.getElementById("myBtn").onclick = function() {
  document.getElementById("myModal").style.display = "block";
};
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap");
* {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Roboto", sans-serif;
}

p {
  width: 400px;
  margin-top: 10px;
}

hr {
  margin-top: 20px;
}

#myBtn {
  padding: 5px 10px;
  margin: 10px;
  position: absolute;
  top: 50px;
  left: 50px;
  cursor: pointer;
}

.page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.modal {
  display: none;
  width: 400px;
  padding: 20px;
  text-align: center;
  border: 1px solid #000;
  border-radius: 10px;
  background-color: #fff;
}

.modal:after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  z-index: -1;
  opacity: 0.5;
}

#close {
  float: right;
  padding: 2px 5px;
  background: transparent;
  border: none;
  outline: none;
  font-size: 20px;
  cursor: pointer;
}
<button id="myBtn">Модальное окно</button>
<div class="page">
  <div class="modal" id="myModal">
    <div class="header">
      <button id="close">&times;</button>
      <h1>Заголовок</h1>
      <hr>
    </div>
    <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Veritatis deleniti, dolores illum iure et optio laboriosam quibusdam veniam reprehenderit mollitia delectus porro vel id voluptate! Omnis amet officia ea veritatis?</p>
  </div>
</div>

Codepen

3
  • 2
    что бы after/before был как бы в body но не задавал полосы прокрутки - надо его делать фиксированным ..дальше если что то не ясно пишите : codepen.io/topicstarter/pen/MWjZLEm - а код надо указывать в теле вопроса а не в песочнице 17 янв 2021 в 0:38
  • Не понятно, что именно хочет реализовать автор...
    – Air
    17 янв 2021 в 4:06
  • Где вопрос.......???
    – Air
    17 янв 2021 в 4:06

1 ответ 1

0

Если правильно понял, то

#myBtn{z-index:1}
.page {position:relative;z-index:2}
.modal:after {z-index:-1}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.