BCA Student Stories & UpdatesLive
CSS Positioning: Static, Relative, Absolute & Fixed
CSS Positioning takes elements out of their natural document flow and pins them to coordinate offsets relative to parents, viewports, or ancestor bounds.
Day 13 Step-by-Step Practical Flow
🎯1. What You Will Learn Today
CSS Positioning: Static, Relative, Absolute & Fixed — Comprehensive Practical Guide
Har concept ko visual mental models, code anatomy aur practical industry tips ke sath samjhein.
CSS Positioning takes elements out of their natural document flow and pins them to coordinate offsets relative to parents, viewports, or ancestor bounds.
"Relative is like claiming your chair in a room. Absolute is sticking a sticky note on the corner of that chair. Fixed is taping a sticker directly onto the camera lens."
👨🏫3. Teacher Demonstration Code
Parent uses position: relative; Badge uses position: absolute.
<style>
.course-card {
position: relative;
width: 320px;
padding: 24px;
background: #ffffff;
border: 2px solid #000000;
border-radius: 16px;
}
.pro-badge {
position: absolute;
top: 12px;
right: 12px;
background: #2563eb;
color: #ffffff;
padding: 4px 10px;
font-size: 11px;
font-weight: bold;
border-radius: 8px;
}
</style>
<div class="course-card">
<span class="pro-badge">FEATURED</span>
<h3>BCA Practical Lab</h3>
<p>Hands-on industry coding system.</p>
</div>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 13 Practical Task Test Studio
Add `position: relative;` to .card-container.
Add `position: absolute;`, `top: 10px;`, and `right: 10px;` to .card-badge.
Spot the Bug: Absolute Child Escaping Outside Container
Tap or click on the exact line below that contains the error:
Click any code line.card-wrapper { /* Missing position: relative on container! */ width: 400px;}.close-btn { position: absolute; top: 10px; right: 10px; /* Button shoots to the top-right corner of the whole screen! */}Senior Developer Forensic Analysis:
An absolute child looks for the nearest positioned ancestor. If no parent has position: relative/absolute, it positions relative to the <body> tag!
📝Independent Practice: Assignment
📄 modal-overlay.htmlHomework Task: Pinned Bottom Notification Bar
- •Create folder `day-13` with `index.html`.
- •Build a long scrolling page with several dummy paragraphs.
- •Create a bottom announcement bar styled with `position: fixed; bottom: 0; left: 0; width: 100%;`.
- •Add a high `z-index: 100` so it stays floating above all scrolling page content.
Open Visual Studio Code on your PC (code .), create modal-overlay.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">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BCA Day 13 - CSS Positioning & Modal Dialog</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Segoe UI', Tahoma, sans-serif;
background: #0f172a;
color: white;
padding: 32px;
min-height: 200vh; /* demonstrate sticky/fixed behavior */
}
/* Fixed trigger button at bottom right */
.floating-help-btn {
position: fixed;
bottom: 24px;
right: 24px;
padding: 12px 20px;
border-radius: 50px;
background: #2563eb;
color: white;
border: none;
font-weight: bold;
cursor: pointer;
box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
z-index: 10;
}
/* Fixed Modal Backdrop Overlay */
.modal-backdrop {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.75);
backdrop-filter: blur(4px);
display: flex;
align-items: center;
justify-content: center;
z-index: 50;
}
/* Modal Card with Relative Position for Absolute Close Button */
.modal-card {
position: relative;
background: #1e293b;
border: 1px solid #334155;
padding: 28px;
border-radius: 16px;
max-width: 440px;
width: 90%;
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}
.modal-close-btn {
position: absolute;
top: 14px;
right: 14px;
background: #334155;
border: none;
color: white;
width: 28px;
height: 28px;
border-radius: 50%;
cursor: pointer;
font-weight: bold;
}
.modal-card h2 { font-size: 18px; color: #38bdf8; margin-bottom: 8px; }
.modal-card p { font-size: 13px; color: #cbd5e1; line-height: 1.5; margin-bottom: 16px; }
.btn-action {
width: 100%;
padding: 10px;
background: #2563eb;
border: none;
border-radius: 8px;
color: white;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<h1>CSS Positioning: Static, Relative, Absolute, Fixed</h1>
<p style="color: #94a3b8; margin-top: 8px;">Scroll down to verify the floating button stays anchored to the viewport.</p>
<!-- Modal Dialog -->
<div class="modal-backdrop">
<div class="modal-card">
<button class="modal-close-btn" onclick="alert('Close clicked')">✕</button>
<h2>BCA Practical Viva Verification</h2>
<p>Demonstrating position: fixed (modal backdrop covering 100vw/100vh) and position: absolute (close button pinned to top-right).</p>
<button class="btn-action" onclick="alert('Submission Approved!')">Confirm Submission</button>
</div>
</div>
<button class="floating-help-btn" onclick="alert('Help desk active')">💬 Ask Mentor</button>
</body>
</html>🎓4. Viva Check: Mandatory Conceptual Test
Why must a parent container have `position: relative` when placing an `absolute` child inside it?
5. Mandatory Step: Push to GitHub to Unlock Next Lesson
Target Repo: html-css-projects
Exact GitHub Setup Guide & Expected Structure
Day 13 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-13/ 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 13 freely! To officially submit your GitHub repository and unlock subsequent days in your portfolio, please complete Day 12: CSS Display Property: Block, Inline, Inline-Block & None first.
Complete Day 12 First