index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notification Slide-In</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Notification Slide-In</h1>
<p>Click the button below to trigger a notification.</p>
<button class="notification-show">Show Notification</button>
<div id="notification" class="notification">
<p class="notif-title">New Message</p>
<p>This is a notification sliding in from the right.</p>
<button class="notification-close">Close</button>
</div>
<script src="script.js"></script>
</body>
</html>
style.css
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 20px;
background: linear-gradient(to right, #6a11cb, #2575fc);
color: #fff;
min-height: 100vh;
overflow: hidden;
}
h1 {
text-align: center;
margin-top: 60px;
}
p {
text-align: center;
font-size: 18px;
}
button {
display: block;
margin: 30px auto;
padding: 12px 24px;
font-size: 16px;
font-weight: bold;
color: white;
background-color: #ff6f61;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.3s ease;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
button:hover {
background-color: #e85a4f;
}
/* Notification */
.notification {
position: fixed;
top: 20px;
right: -350px; /* off-screen */
width: 200px;
padding: 10px;
background: #ffffff;
color: #333;
border-left: 6px solid #2575fc;
border-radius: 8px;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
transition: right 0.5s ease-in-out;
z-index: 9999;
}
.notification p {
font-size: 14px;
text-align: left;
margin: 5px 0;
}
.notification.show {
right: 20px;
}
.notification .notif-title {
margin-top: 0;
color: #2575fc;
font-weight: bold;
font-size: 16px;
margin-bottom: 0;
}
.notification-close {
margin: 0;
background: #2575fc;
border: none;
color: #fff;
padding: 8px 16px;
font-size: 14px;
border-radius: 5px;
cursor: pointer;
float: right;
}
.notification-close:hover {
background: #1e5edc;
}
script.js
const notification = document.getElementById("notification");
const showButton = document.querySelector(".notification-show");
const closeButton = document.querySelector(".notification-close");
showButton.addEventListener("click", () => {
notification.classList.add("show");
});
closeButton.addEventListener("click", () => {
notification.classList.remove("show");
});