Java script: Button form

Task: create a simple popup window

Java Script code:

function togglePopup() {
  let pop = document.getElementById('my-popup');
  pop.classList.toggle("show");
}

HTML code

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="./style.css">
</head>

<body class="body">
  <div class="all-code-position">
    <div class="main-div">
      <button class="btn" id="btn" onclick="togglePopup()">Tick</button>

      <div class="popup" id="my-popup">
        <div class="answer-text">Do you like fruits?</div>
        <div class="answers">
          <button class="answer" onclick="togglePopup()">Yes</button>
          <button class="answer" onclick="togglePopup()">No</button>
        </div>
      </div>

    </div>
  </div>

</body>
<script src="./script.js"></script>

</html>

CSS code

.body {
  margin: 0;
  padding: 0;
}

.all-code-position {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.btn {
  background-color: skyblue;
  width: 200px;
  height: 75px;
  border: 1px solid black;
  border-radius: 10px;
  font-size: 40px;
  box-shadow: 3px 3px 3px 3px grey;
  align-items: center;
  justify-content: center;
}

.popup {
  width: 400px;
  height: 150px;
  border: 1px solid black;
  border-radius: 10px;
  box-shadow: 6px 6px 6px 6px grey;
  background-color: skyblue;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

}

.answers {
  display: flex;
  flex-direction: row;
}

.answer-text {
  font-size: 40px;
}

.answer {
  background-color: skyblue;
  width: 100px;
  height: 50px;
  border: 1px solid black;
  border-radius: 10px;
  font-size: 40px;
  box-shadow: 3px 3px 3px 3px grey;
  margin: 10px;
}

.popup.show {
  display: flex;
}

.btn:hover {
  background-color: #89dbeb;
  box-shadow: 2px 2px 2px 2px rgb(135, 135, 135);
  width: 190px;
  height: 72px;
  font-size: 38px;
}

.answer:hover {
  font-size: 38;
}

Result

Leave a Reply

Your email address will not be published. Required fields are marked *




Enter Captcha Here :