Html code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SweetSavor Chocolates</title>
<link rel="stylesheet" href="C:\Users\SA\OneDrive\Documents\6TH SEM BCOM\WED
DESIGN\chocolate style.css">
</head>
<body>
<header>
<h1>SweetSavor Chocolates</h1>
<nav>
<ul>
<li><a href="#about">About Us</a></li>
<li><a href="#products">Products</a></li>
<li><a href="#features">Features</a></li>
<li><a href="#offers">Offers</a></li>
<li><a href="#contact">Contact Us</a></li>
<li><button id="loginBtn">Login</button></li>
</ul>
</nav>
</header>
<main>
<section id="about">
<h2>About Us</h2>
<p>Welcome to SweetSavor Chocolates, where we craft the finest chocolates with love
and care.</p>
</section>
<section id="products">
<h2>Products</h2>
<!-- Product images and descriptions -->
</section>
<section id="features">
<h2>Features</h2>
<p>Our chocolates are made from premium ingredients sourced from around the world,
ensuring the highest quality and taste.</p>
</section>
<section id="offers">
<h2>Offers</h2>
<!-- Exciting festive season offers -->
</section>
<section id="contact">
<h2>Contact Us</h2>
<!-- Contact form or contact information -->
</section>
</main>
<footer>
<p>© 2024 SweetSavor Chocolates. All rights reserved.</p>
</footer>
<!-- Login Modal -->
<section id="loginModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>Login</h2>
<form id="loginForm">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<button type="submit">Login</button>
</form>
<p id="loginError" class="error-message"></p>
</div>
</section>
<script src="C:\Users\SA\OneDrive\Documents\6TH SEM BCOM\WED DESIGN\
chcolatejava.js"></script>
</body>
</html>
Css code:
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #f9e5d9;
padding: 20px;
text-align: center;
}
nav ul {
list-style-type: none;
}
nav ul li {
display: inline;
margin-right: 20px;
}
nav ul li a {
text-decoration: none;
color: #333;
font-weight: bold;
}
main {
padding: 20px;
}
footer {
background-color: #f9e5d9;
text-align: center;
padding: 10px 0;
}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: #fefefe;
margin: 10% auto;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
max-width: 400px;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
.error-message {
color: red;
margin-top: 10px;
}
#loginForm label {
display: block;
margin-bottom: 5px;
}
#loginForm input[type="text"],
#loginForm input[type="password"],
#loginForm button {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
#loginForm button {
background-color: #4CAF50;
color: white;
font-weight: bold;
cursor: pointer;
}
#loginForm button:hover {
background-color: #45a049;
}
Javascript:
// Get the modal
var modal = document.getElementById("loginModal");
// Get the button that opens the modal
var loginBtn = document.getElementById("loginBtn");
// Get the <span> element that closes the modal
var closeBtn = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
loginBtn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
closeBtn.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
// Login form submission
document.getElementById("loginForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
// Get username and password values
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
// Check if username and password are correct (dummy validation)
if (username === "admin" && password === "password") {
// If correct, redirect to a dashboard or another page
alert("Login successful!");
// Redirect to dashboard or another page
// window.location.href = "dashboard.html";
modal.style.display = "none"; // Close the login modal
} else {
// If incorrect, display error message
document.getElementById("loginError").innerText = "Invalid username or password.";
}
});