BCA Student Stories & UpdatesLive
Dynamic Modal Dialogs, Overlay Mechanics & Keyboard Accessibility
Modal dialogs are essential UI components for confirmation prompts, authentication gates, image lightboxes, and detail drawers. Crafting professional modals requires careful orchestration of CSS overlays, body scroll prevention, event propagation handling, and keyboard accessibility (ESC key dismissal).
Day 35 Step-by-Step Practical Flow
🎯1. What You Will Learn Today
Dynamic Modal Dialogs, Overlay Mechanics & Keyboard Accessibility — Comprehensive Practical Guide
Har concept ko visual mental models, code anatomy aur practical industry tips ke sath samjhein.
Modal dialogs are essential UI components for confirmation prompts, authentication gates, image lightboxes, and detail drawers. Crafting professional modals requires careful orchestration of CSS overlays, body scroll prevention, event propagation handling, and keyboard accessibility (ESC key dismissal).
"Think of a modal dialog like a spotlight on a theatre stage: the rest of the stage is darkened and muted, directing 100% of the audience attention onto the central scene until the spotlight is turned off."
👨🏫3. Teacher Demonstration Code
Notice how click propagation is controlled and the Escape key listener is registered cleanly.
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: 'Segoe UI', sans-serif; background: #060c18; color: #fff; padding: 24px; }
.backdrop {
position: fixed; inset: 0; background: rgba(0,0,0,0.75);
backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center;
z-index: 1000;
}
.backdrop.active { display: flex; }
.modal-box {
background: #0c1328; border: 1px solid #1e293b; border-radius: 14px;
padding: 24px; max-width: 440px; width: 90%; box-shadow: 0 20px 40px rgba(0,0,0,0.6);
transform: scale(0.95); transition: transform 0.2s;
}
.backdrop.active .modal-box { transform: scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.close-btn { background: none; border: none; color: #94a3b8; font-size: 20px; cursor: pointer; }
.modal-footer { margin-top: 20px; display: flex; justify-content: flex-end; gap: 8px; }
button.primary { background: #2563eb; color: #fff; border: none; padding: 10px 16px; border-radius: 6px; cursor: pointer; }
</style>
</head>
<body>
<h2>🎓 BCA Portal Confirmation Engine</h2>
<button class="primary" id="openModalBtn">Open Submission Modal</button>
<div class="backdrop" id="modalBackdrop">
<div class="modal-box" id="modalContent">
<div class="modal-header">
<h3>Confirm Practical Submission</h3>
<button class="close-btn" id="closeBtn">✕</button>
</div>
<p style="color:#94a3b8;margin-top:12px;">Are you ready to submit Day 35 practical tasks to the evaluation studio? This action will sync with your profile.</p>
<div class="modal-footer">
<button id="cancelBtn" style="background:#334155;color:#fff;border:none;padding:10px 16px;border-radius:6px;cursor:pointer;">Cancel</button>
<button class="primary" id="confirmBtn">Confirm & Submit</button>
</div>
</div>
</div>
<script>
const backdrop = document.getElementById("modalBackdrop");
const modalContent = document.getElementById("modalContent");
const openBtn = document.getElementById("openModalBtn");
const closeBtn = document.getElementById("closeBtn");
const cancelBtn = document.getElementById("cancelBtn");
function openModal() {
backdrop.classList.add("active");
document.body.style.overflow = "hidden"; // Prevent body scroll
}
function closeModal() {
backdrop.classList.remove("active");
document.body.style.overflow = ""; // Restore body scroll
}
openBtn.addEventListener("click", openModal);
closeBtn.addEventListener("click", closeModal);
cancelBtn.addEventListener("click", closeModal);
// Close on backdrop click (outside modal content)
backdrop.addEventListener("click", (e) => {
if (e.target === backdrop) closeModal();
});
// Close on ESC key press
window.addEventListener("keydown", (e) => {
if (e.key === "Escape" && backdrop.classList.contains("active")) {
closeModal();
}
});
</script>
</body>
</html>2. Hands-On Practical Lab: Follow Instructions in VS Code
Code like a professional software engineer! Follow the step-by-step instructions below in Visual Studio Code (VS Code) on your PC, test your output locally, and push to GitHub.
Day 35 Practical Task Test Studio
Listen for keydown events on window and invoke closeModal() if e.key === "Escape".
Set document.body.style.overflow = "hidden" when opening the modal and restore to "" on close.
Backdrop Click Accidentally Triggered Inside Modal Content Bug
Tap or click on the exact line below that contains the error:
Click any code lineconst backdrop = document.querySelector(".backdrop");const box = document.querySelector(".modal-box"); // ❌ Bug: Clicking anywhere inside the modal box triggers backdrop click listener!backdrop.addEventListener("click", () => { closeModal();});Senior Developer Forensic Analysis:
Because events bubble up from child elements to parent elements, clicking inside the modal box causes the click event to bubble up to the backdrop, immediately closing the modal whenever users try to interact with it.
📝Independent Practice: Assignment
📄 index.htmlBCA Student Profile Inspector & Detail View Modal
- •Create a student list with 4 student cards displaying Name, Roll Number, and View Details buttons.
- •Clicking View Details opens a centered modal with animated scale transition displaying complete profile information.
- •Ensure the modal closes via: ✕ button, Cancel button, Backdrop click, and Escape key.
- •Prevent background body scrolling when modal is open.
Open Visual Studio Code on your PC (code .), create index.html, paste this complete step-by-step verified code, test in your browser, and push to your GitHub repo:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>BCA Day 35 - Profile Modal</title>
<style>
body { font-family: 'Segoe UI', sans-serif; background: #060c18; color: #fff; padding: 24px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; max-width: 680px; margin: auto; }
.card { background: #0c1328; border: 1px solid #1e293b; padding: 16px; border-radius: 10px; text-align: center; }
button { padding: 8px 14px; background: #2563eb; color: #fff; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; margin-top: 10px; }
.backdrop {
position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(4px);
display: none; align-items: center; justify-content: center; z-index: 1000;
}
.backdrop.active { display: flex; }
.modal { background: #0c1328; border: 1px solid #334155; padding: 24px; border-radius: 12px; width: 90%; max-width: 400px; }
</style>
</head>
<body>
<div class="grid">
<div class="card">
<h3>Amit Verma</h3>
<p style="color:#94a3b8;">Roll: BCA-2401</p>
<button onclick="showDetails('Amit Verma', 'BCA-2401', 'Web Development Track', '94% Attendance')">View Profile</button>
</div>
<div class="card">
<h3>Sneha Gupta</h3>
<p style="color:#94a3b8;">Roll: BCA-2402</p>
<button onclick="showDetails('Sneha Gupta', 'BCA-2402', 'Data Analytics Track', '98% Attendance')">View Profile</button>
</div>
</div>
<div class="backdrop" id="modalBackdrop">
<div class="modal" id="modalBox">
<h3 id="modalName">Student Details</h3>
<p id="modalRoll" style="color:#94a3b8;"></p>
<p id="modalTrack" style="color:#38bdf8;"></p>
<p id="modalAttendance" style="color:#10b981;font-weight:bold;"></p>
<button onclick="closeModal()" style="background:#ef4444;width:100%;">Close Modal (Esc)</button>
</div>
</div>
<script>
const backdrop = document.getElementById("modalBackdrop");
function showDetails(name, roll, track, att) {
document.getElementById("modalName").textContent = name;
document.getElementById("modalRoll").textContent = "Roll Number: " + roll;
document.getElementById("modalTrack").textContent = "Specialization: " + track;
document.getElementById("modalAttendance").textContent = att;
backdrop.classList.add("active");
document.body.style.overflow = "hidden";
}
function closeModal() {
backdrop.classList.remove("active");
document.body.style.overflow = "";
}
backdrop.addEventListener("click", (e) => {
if (e.target === backdrop) closeModal();
});
window.addEventListener("keydown", (e) => {
if (e.key === "Escape") closeModal();
});
</script>
</body>
</html>🎓4. Viva Check: Mandatory Conceptual Test
Why should document.body.style.overflow be set to "hidden" when an overlay modal opens?
5. Mandatory Step: Push to GitHub to Unlock Next Lesson
Target Repo: html-css-projects
Exact GitHub Setup Guide & Expected Structure
Day 35 RequirementsFollow these exact folder and file names to prevent verification errors.
index.html: Avoid spaces or custom names like Alan Turing..html or Index.HTML. Linux/GitHub servers are strictly case-sensitive.day-35/ for today so you don't overwrite previous days.main.You are welcome to read all notes, inspect code snippets, and practice all exercises of Day 35 freely! To officially submit your GitHub repository and unlock subsequent days in your portfolio, please complete Day 34: DOM Event Delegation, Event Bubbling & Dynamic List Architecture first.
Complete Day 34 First