Hello wizards, I hope you are doing great. Today in this blog you’ll learn how to create the "Pop-Up" project using HTML, CSS & JavaScript.
Preview
In the above video, you’ve seen the preview of the "Pop-Up" project and I hope now you are able to create this type of project. If not, I have provided all the HTML CSS and JavaScript code below.
Pop-Up [Source Code]
To get the following HTML, CSS & JS code for the Pop-Up project. You need to create three files one is a HTML file, second one is a CSS file and the another one is JS file. After creating these three files then you can copy-paste the given codes on your document.
Remember, you’ve to create a file with .html extension for HTML code, .css extension for CSS code and .js for JavaScript code.
You can also download all source code files from the given download button.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pop-Up</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<button type="submit" class="submitBtn">SUBMIT</button>
<div class="pop-up">
<img src="check.svg" alt="">
<h2>Thank You</h2>
<p>Thanks for submitting your response...!</p>
<button class="okBtn">OK</button>
</div>
</div>
<script src="index.js"></script>
</body>
</html>
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100%;
background-color: purple;
}
button {
font-size: 18px;
border-radius: 50px;
border: none;
background-color: #ff0000;
color: white;
font-weight: 600;
letter-spacing: 2px;
cursor: pointer;
}
.submitBtn {
width: 180px;
height: 50px;
}
.submitBtn:active {
transform: scale(0.95);
}
.pop-up {
width: 400px;
position: absolute;
top: 0;
left: 50%;
transform: translate(-50%, -50%) scale(0.01);
background-color: white;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 20px;
border-radius: 20px;
visibility: hidden;
transition: all 0.5s ease-in-out;
}
.pop-up-open {
visibility: visible;
top: 50%;
transform: translate(-50%, -50%) scale(1);
}
.pop-up img {
width: 100px;
position: absolute;
top: -27%;
left: 38%;
}
.pop-up h2 {
margin-top: 30px;
color: #ff0000;
}
.pop-up p {
font-size: 15px;
text-align: center;
margin: 15px 0;
}
.pop-up .okBtn {
width: 80px;
height: 40px;
}
const submitBtnEl = document.querySelector(".submitBtn");
const okBtnEl = document.querySelector(".okBtn");
const popUpEl = document.querySelector(".pop-up");
submitBtnEl.addEventListener("click",()=>{
popUpEl.classList.add("pop-up-open");
})
okBtnEl.addEventListener("click",()=>{
popUpEl.classList.remove("pop-up-open");
})
