Unit 1 home
FSWD · MERN CLASS 11 / 48 60-MIN SESSION WHY THINGS SIT WHERE THEY SIT
UNIT 1 · WEB BASICS, HTML & CSS PART A · CLASS 11 OF 12 UI23PC510CS · THEORY

Today's X-ray

Every element you have ever written is a box. Today you get X-ray vision.

Class 10 loaded the paint — colours, fonts, one style.css dressing the whole site. But two mysteries were left standing, on purpose: why did margin: 0 auto need a width to centre that form? And what exactly were the padding and margin lines doing inside .dish? The answer to both is the CSS Box Model — the four nested layers every element is made of — plus position and display: the properties that decide where things sit and why.

Walk out of this room able to…

Name the four layers of the box model in order — and compute an element's true total width
Read any element's REAL box in Chrome DevTools' Computed panel — the professional's daily habit
Place elements deliberately with position — including the relative + absolute pair every badge and tooltip uses
Answer the PYQ: explain the box model + text that shows blue on screen, red on paper
TODAY, POINT BY POINT
01The box model — content, padding, border, margin, drawn to scaleTHE PICTURE
02Activity 1 — DevTools inspection: read a real dish card's box, no guessingTRY IT
03Activity 1 verdict — the Computed panel decodedSOLUTION
04PYQ · P1·Q16a · 4m — box model + blue-on-screen / red-on-printEXAM Q
05box-sizing: border-box — the width that lied, then told the truthIDEA
06position — static, relative, absolute, fixed: the anchor ruleIDEA
07Activity 2 — predict the render: where does the price tag land?TRY IT
08display — block, inline, inline-block: the other half of stackingIDEA
09Activity 3 — broken-site debugging: the badge that escaped its cardTRY IT
10Worked example — poshtik's header, boxed and positioned properlyBUILD
11Take-home kit — the layout property card, your folder, homeworkWRAP
NOTHING NEW TO DOWNLOAD TODAY

Every box we X-ray today already exists — the .dish cards, the header, the nav — all styled by the style.css you typed in Class 10. Today's only new tool is Chrome DevTools, and it has been sitting inside your browser all along: press F12 and it opens. Nothing to install, nothing to fetch.

CATCH-UP CORNER · MISSED CLASS 10?

Grab the Class 9 asset pack (from the Class 9 opener) for the caught-up poshtik-campus\ folder, then open Class 10, Part 5 and type its 19-line style.css into existence — twenty minutes, and it's the exact file today inspects. Every padding, border and margin value we read in DevTools today comes from those 19 lines, so don't skip the typing.

The picture that explains everything

Content, padding, border, margin — four layers, inside out.

Take any element — a heading, a paragraph, a .dish card — and the browser wraps it in the same four rectangles, every single time. Content is the text or image itself. Padding is breathing room inside the border. Border is the visible edge. Margin is the push outside — the gap to the neighbours. Learn to see these four and every layout question for the rest of your career becomes "which layer am I changing?"

MARGIN outside push · transparent · 12px 0 BORDER the visible edge · 2px solid seagreen PADDING inside breathing room · 12px · mintcream shows through CONTENT Ragi Idli Bowl — text, image, children this is what width: 300px measures (for now…) width: 300px READ INSIDE-OUT 1 · content the thing itself 2 · padding space inside edge 3 · border the edge itself 4 · margin · space outside

This is your own card, to scale: the values in the diagram are not invented — they are the exact lines you typed into style.css in Class 10: .dish { width: 300px; padding: 12px; border: 2px solid seagreen; margin: 12px 0; }. You have been using all four layers since last class. Today you can finally name what you were doing.

Now the arithmetic that catches everyone. One press per line — watch the running total on the right.

box-width-demo.html · plain HTML first, then the style rulesHTML BUILDS, THEN CSS — ONE PRESS AT A TIME
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <title>Box width demo</title>
6</head>
7<body>
8 <article class="dish">Jonna Rotte Wrap</article> <!-- the box being measured -->
9</body>
10</html>
·/* HTML is complete & plain above. Now add a <style> — one rule per press ↓ */
11<style> .dish { /* exactly what you wrote in Class 10 */
12 width: 300px; /* content only! */
13 padding: 12px; /* +12 left, +12 right */
14 border: 2px solid seagreen; /* +2, +2 */
15 margin: 12px 0; /* outside — not part of the box's own width */
16 background-color: mintcream;
17} </style>
··/* true on-screen width: */
··/* 300 + 12 + 12 + 2 + 2 = 328px — not 300 */
REAL OUTPUT — PLAIN BOX FIRST, THEN EACH RULE
box-width-demo.html
file:///C:/Users/student/Desktop/fswd-practice/class-11/box-width-demo.html
Jonna Rotte Wrap
← on-screen width is now 300 + 24 + 4 = 328px (shown to scale) ↑ PLAIN HTML — A BARE ARTICLE, FULL WIDTH, NO CSS YET

Plain box on screen — no width, padding, or border yet. (the HTML above is complete & unstyled)

300px — the content rectangle. what width: sets

+ 24px — padding, both sides. running total: 324

+ 4px — border, both sides. running total: 328

margin: excluded — it positions the box; it is not part of it.

TRUE WIDTH = 328px. The width property lied to you — politely.

Say the sentence: by default, width sets the content layer only — padding and border are added on top. This surprise has broken a million layouts. Part 5 installs the modern fix; first, go verify the 328 with your own eyes in Activity 1.

Now watch the four layers arrive one at a time. The right side starts as a bare box — just text, no padding, no border, no margin. Press once per rule and each box-model layer lands on the live box: first the content padding pushes the text off the edges, then the seagreen border draws itself, then the margin pushes the whole box inward. Plain HTML first — then CSS, in sync, never all at once.

.dish rules · applied to the live boxONE PRESS = ONE LAYER ON THE BOX
·/* the <article class="dish"> box is already on screen (bare) */
1.dish { width: 220px; background: mintcream; }
2.dish { padding: 14px; } /* content layer gets breathing room */
3.dish { border: 3px solid seagreen; } /* border layer */
4.dish { margin: 18px; } /* margin layer — outside the box */
THIS OUTPUT IS REAL — PLAIN BOX FIRST, THEN EACH LAYER
box-layers-demo.html
file:///C:/Users/student/Desktop/fswd-practice/class-11/box-layers-demo.html
Jonna Rotte Wrap

Before any press: a bare box, text touching every edge. Each press adds exactly one layer — you can press Back to peel them off again.

Four layers, four presses. Padding grows the box inward-to-outward; the border wraps it; the margin holds it away from its neighbours. That is the box model you just computed to 328px — now seen assembling itself.
GOING DEEPER — WHERE DID THE GAP GO? (MARGIN COLLAPSE)

Two .dish cards each carry margin: 12px 0 — so the gap between two stacked cards should be 12 + 12 = 24px, right? Measure it in DevTools: it's 12px. Vertical margins between stacked blocks collapse: the browser keeps only the larger of the two, not the sum. This is deliberate (it keeps repeated paragraphs evenly spaced) but it startles everyone once. Horizontal margins never collapse — only vertical ones do.

ACTIVITY 1 · DEVTOOLS INSPECTION · ~8 MINUTES

Don't take my 328 on faith. Go read the browser's own ruler.

Chrome keeps a live X-ray of every element's box — the Computed panel. Your job: open your own menu.html, inspect one dish card, and read off its four layers from the browser itself. No guessing, no trusting slides — the browser tells you what it actually drew.

YOUR INSPECTION MISSION
SETUP
Open menu.html (your poshtik-campus\ copy, styled by Class 10's style.css) in Chrome. Press F12, or right-click any dish card and choose Inspect.
STEPS
  • In the Elements tab, click the <article class="dish"> for Ragi Idli Bowl.
  • In the right-hand pane, open the Computed tab and scroll to the coloured box-model drawing.
  • Write down the four numbers it shows: content width, padding, border, margin.
  • Add them up left-to-right and check the total against Part 2's arithmetic.
RECORD
Three answers in your notebook: ① the content width Chrome reports · ② the full left-to-right sum · ③ which layer is transparent in the drawing (hover each layer — Chrome highlights it on the page in the same colour).
WHERE THIS WORK LIVES
FILESNo new files — you are reading, not writing. DevTools inspects the page in memory.
GIT?No — nothing changed on disk. Inspection never touches your repo.

Inspect honestly first. Reading the Computed panel is the single most-used professional habit this course teaches.

SOLUTION · THE COMPUTED PANEL, DECODED
CHROME DEVTOOLS — WHAT YOUR SCREEN SHOWS
StylesComputedLayout
margin 12 12 0 0 border 2 padding 12 300 × 96.5
Reading it left to right: 0 + 2 + 12 + 300 + 12 + 2 + 0 = 328px — the browser confirms Part 2's arithmetic to the pixel. ③ The margin layer is the transparent one: hover it and Chrome paints an orange halo outside the card, on space the card doesn't own but pushes clear.

Why 96.5 and not a round number? You never set a height — so the browser computed one from the text inside. Width was pinned by width: 300px; height flows from content. That asymmetry (fixed width, flowing height) is how almost every real card on the web behaves.

Solved PYQ · straight from the papers

Four marks, two ideas: the box model + a colour that changes when printed.

You just measured all four layers with your own eyes — this question is now a victory lap. The second half adds one new trick: @media print, a rule block that applies only when the page is printed. Watch it work for real below, then take the model answer one point per press.

PREVIOUS YEAR QUESTION P1 · Q16(a)4 MARKSUNIT 1

asked verbatim!Explain the CSS Box Model. Write CSS so that a heading appears blue on screen but prints in red. [4M]

Model answer — box model first, then the two-colour trick :

1
The CSS Box Model says every element is drawn as four nested rectanglescontent (the text/image itself), padding (space inside the border), border (the visible edge), margin (transparent space outside, pushing neighbours away).✓ 1m
2
By default width sets the content layer only — the true on-screen width is width + padding + border (both sides). Example: 300 + 12+12 + 2+2 = 328px.✓ 1m
3
Screen colour is the normal rule: h1 { color: blue; } — this is what every monitor shows.✓ 1m
4
Print colour rides a media query: @media print { h1 { color: red; } } — the block applies only while printing; on paper the same heading comes out red. Never write two separate pages — one page, two media rules.✓ 1m
Beyond the marks: @media print is the tiny cousin of @media (max-width: …) — the responsive queries Class 12 is built on. Nail this 4-marker and you have already met next class's core syntax.

Now prove the answer is real. The panel types the exact CSS; the preview beside it is a working simulation — press the two buttons and watch the same heading change ink.

print-demo.html · plain HTML first, then the two colour rulesHTML BUILDS, THEN CSS — ONE PRESS PER LINE
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <title>Screen vs print</title>
5</head>
6<body>
7 <h1>Poshtik Campus Menu</h1>
8 <p>Same file, two inks.</p>
9</body>
10</html>
·/* HTML is complete & plain above (default black text). Now add a <style> ↓ */
11<style>
12 h1 { color: blue; } /* every screen */
13 @media print {
14 h1 { color: red; } /* paper only */
15 }
16</style>
THIS OUTPUT IS REAL — PLAIN HTML FIRST, THEN EACH RULE
file:///C:/Users/student/Desktop/fswd-practice/class-11/print-demo.html
VIEWING · ON SCREEN

Poshtik Campus Menu

Same file, two inks.

↑ PLAIN HTML — NO CSS YET, SO BOTH LINES ARE DEFAULT BLACK
SIMULATE THE MEDIUM — SAME FILE, TWO RENDERS
Try it on your machine too: save the file, open it, press Ctrl+P — Chrome's print preview shows the heading in red while the tab behind it stays blue. One file, two media, zero duplication.
SAVE THIS AS
FOLDERC:\Users\student\Desktop\fswd-practice\class-11\
FILENAMEprint-demo.html — the 23 lines above, exactly
GIT?No — exam practice lives in the sandbox. Throwaway file; poshtik-campus\ alone carries commits.

Marks anatomy: 2 marks for the four layers named in order with the width arithmetic, 2 marks for the two colour rules — and the @media print block is the half most students drop. Write both rules; label them "screen" and "print" in comments exactly as the panel does.

Error first — watch it break, then fix it

Two half-width columns that refuse to sit side by side.

Here is the layout everyone writes in week one: two columns, each width: 50%, expecting them to share the row. They don't — the second one wraps below. You now know exactly why: 50% + padding + border is more than 50%. Press the buttons in the output and watch box-sizing: border-box repair it live.

two-columns.html · plain HTML first, then the rules — then the one-line fixHTML BUILDS, THEN CSS — ONE PRESS PER LINE
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <title>Two columns</title>
6</head>
7<body>
8 <div class="col">Jonna Rotte Wrap — Rs. 60</div> <!-- column one -->
9 <div class="col">Ragi Idli Bowl — Rs. 50</div> <!-- column two — the one that wraps -->
10</body>
11</html>
·/* two plain divs on screen (full-width, stacked). Now add a <style> ↓ */
12<style> .col { /* THE PLAN: two columns, half the row each */
13 float: left; /* sit on one row — Class 12 tells float's full story */
14 width: 50%;
15 padding: 12px; /* + on top of the 50%! */
16 border: 2px solid seagreen; /* + again */
17 background-color: mintcream;
18 } </style>
··/* each col = 50% + 24 + 4 > half the row */
··/* 2 cols > 100% — the second one WRAPS */
·· box-sizing: border-box; /* THE FIX — add inside .col, after line 13 */
··/* now width:50% means the WHOLE box is 50% — */
··/* padding + border squeeze INSIDE, content shrinks */
THIS OUTPUT IS REAL — PLAIN HTML FIRST, THEN EACH RULE
file:///C:/Users/student/Desktop/fswd-practice/class-11/two-columns.html
THE ROW · 100% WIDE
Jonna Rotte WrapRs. 60 · high fibre
Ragi Idli BowlRs. 50 · calcium rich
↑ PLAIN HTML — TWO BARE DIVS, FULL WIDTH, STACKED. NO CSS YET ✗ 50% + 24 + 4 each — together they overflow the row; on a real page column two drops BELOW. ✓ border-box: each whole box is exactly 50% — the pair shares one row with room to spare.
TOGGLE THE ONE-LINE FIX
The sentence to keep: border-box makes width mean the whole visible box — padding and border move inside the number instead of stacking on top of it. Professional stylesheets set it on everything, on line one.

The professional opener: real stylesheets start with * { box-sizing: border-box; } — every element, honest widths, forever. From the next time you touch style.css, that line goes at the very top. (We keep today's practice files in the sandbox; the real repo gets it in Class 12's responsive pass, as one deliberate commit.)

GOING DEEPER — WHY ISN'T border-box THE DEFAULT?

History. CSS shipped in 1996 with content-box behaviour, and the web never breaks old pages on purpose — billions of existing sites rely on the old maths. So the sensible behaviour is opt-in: one line, top of the sheet. Old Internet Explorer actually used border-box maths incorrectly on purpose in "quirks mode" — the industry later admitted IE's instinct was the better default, and standardised it as an opt-in property instead.

Where things sit — and who they sit relative to

position — four values, one question: "measured from where?"

Every element starts life in the normal flow — stacked in source order, exactly as your pages have behaved since Class 2. The position property lets one element step out of that queue. The whole topic is a single question asked four ways: when I write top: 10px, 10px from what?

static

The default. The element sits in the normal flow queue. top/right/bottom/left are ignored completely.

Measured from: nothing — it queues.

relative

Nudged from its own normal spot — and, crucially, its original gap in the queue is kept reserved (the ghost you'll see below).

Measured from: where it would have been.

absolute

Pulled out of the queue entirely — its gap closes. It measures from the nearest ancestor that has a position set; if none exists, from the whole page.

Measured from: the nearest positioned ancestor.

fixed

Pinned to the browser window itself. Scrolling never moves it — chat bubbles, cookie bars, "back to top" buttons.

Measured from: the window. Always.

Now watch all four, live. One dish card, one NEW badge. Press each mode button and watch where the badge lands — and read the dashed ghost that marks where it would have been.

position-play.html · plain HTML first, then the mode rules swap inHTML BUILDS, THEN CSS — ONE PRESS PER LINE
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <title>Position play</title>
6</head>
7<body>
8 <article class="dish"> <!-- MODE 4 anchors THIS card -->
9 <h4>Ragi Idli Bowl — Rs. 50</h4>
10 <p>Soft steamed finger-millet idlis.</p>
11 <span class="badge">NEW</span> <!-- the element every mode moves -->
12 </article>
13</body>
14</html>
·/* card + NEW badge on screen, plain (badge queues = static). Now a <style> ↓ */
15<style> .badge { /* MODE 1 · static — default: rule left EMPTY */
·· /* MODE 2 · relative — nudged from its own spot */
·· position: relative; top: -58px; left: 160px; /* ghost stays! */
·· /* MODE 3 · absolute, NO anchored parent — flies to the PAGE corner */
·· position: absolute; top: 10px; right: 10px;
·· /* MODE 5 · fixed — pinned to the window, scroll-proof */
·· position: fixed; right: 12px; bottom: 12px;
·· } /* MODE 4 · keep MODE 3's absolute + ONE new rule on the CARD: */
·· .dish { position: relative; } </style> /* the anchor */
THIS OUTPUT IS REAL — PLAIN HTML FIRST, THEN EACH RULE
file:///C:/Users/student/Desktop/fswd-practice/class-11/position-play.html

Today's Healthy Ten

Ragi Idli Bowl — Rs. 50

Soft steamed finger-millet idlis.

ghost — its spot in the queue NEW
NEW · pinned to the window ↑ PLAIN HTML — NO STYLE SHEET YET, SO NO CARD BOX AND NO PILL
CHOOSE THE BADGE'S POSITION MODE
static: the badge queues politely after the paragraph — top/left would be ignored. This is every element you have ever written so far.

The pair worth memorising: parent { position: relative; } + child { position: absolute; }. The parent volunteers as the measuring frame; the child pins to its corners. Every price tag, every notification dot, every "NEW" ribbon on every shopping site is this exact two-line pattern.

GOING DEEPER — THE FIFTH VALUE

position: sticky is the hybrid: it scrolls normally like relative, then sticks like fixed once it reaches a threshold (top: 0). Section headers in long lists (your phone's contacts app) use it. It's beyond this paper's syllabus — but now the four you DO need each answer the same question: measured from where?

ACTIVITY 2 · PREDICT THE RENDER · ~6 MINUTES

Read the CSS. Say where the price tag lands — before any browser shows you.

This is the exact skill Part 6 built: answer "measured from where?" from code alone. Read both rules, then commit your prediction in writing. The render is deliberately hidden until you unlock — prediction first is the pedagogy.

THE CODE UNDER PREDICTION
MARKUP
A dish card holds a price tag: <article class="dish"> … <span class="price">Rs. 60</span> </article>. The card sits in the middle of a page with other cards above and below it.
THE CSS
.dish { position: relative; width: 300px; } and .price { position: absolute; top: 8px; right: 8px; }
PREDICT
  • Where exactly does Rs. 60 render — measured from which box's corner?
  • Does the card keep a gap where the price tag used to sit in the flow?
  • One-line why: which rule made the card the measuring frame?

A prediction you commit to teaches double: right = confidence, wrong = the exact gap in your model, found cheap.

SOLUTION · THE RENDER + THE WHY
THE ACTUAL RENDER
the card is the frame — the tag pins to ITS corner
Rs. 60

Jonna Rotte Wrap

Sorghum flatbread wrap with sprouts.

Verdicts: ① the tag pins 8px from the CARD's own top-right corner — not the page's — because the card carries position: relative and is therefore the nearest positioned ancestor. ② The flow gap closes: absolute removes the tag from the queue entirely (unlike relative's ghost). ③ Delete the card's position: relative and the tag would fly to the page's top-right corner instead — that failure is Activity 3.

The other half of "why things stack"

display — does this element claim the whole row, or share it?

You have felt this since Class 2 without naming it: a <p> always starts a new line; an <a> sits inside a sentence. That difference IS the display property. block claims the full row and accepts width/height. inline flows within text but ignores width, height and vertical margins. inline-block is the useful hybrid — flows in a row, yet obeys the box properties.

Same three chips, three display modes. Press each button and watch the stacking change — the CSS shown is the only line that differs.

display-play.html · plain HTML first, then one property, three behavioursHTML BUILDS, THEN CSS — ONE PRESS PER LINE
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <title>Display play</title>
6</head>
7<body>
8 <span class="chip">Wraps</span>
9 <span class="chip">Bowls</span>
10 <span class="chip">Drinks</span> <!-- the three chips being switched -->
11</body>
12</html>
·/* three plain chips on screen (inline spans, side by side). Now a <style> ↓ */
13<style> .chip {
14 display: block; /* full row each — stack */
·· display: inline; /* swap in: share the line — width IGNORED */
·· display: inline-block; /* swap in: share the line AND obey width */
15 width: 130px; /* honoured only by block + inline-block */
16 background-color: mintcream; border: 2px solid seagreen;
17 } </style>
THIS OUTPUT IS REAL — PLAIN HTML FIRST, THEN EACH RULE
file:///C:/Users/student/Desktop/fswd-practice/class-11/display-play.html
WrapsBowlsDrinks ↑ PLAIN HTML — BARE SPANS, SO THEY JUST SHARE ONE LINE AS TEXT

block: each chip claims a full row — they stack, and the 130px width is honoured.

SET display: ON ALL THREE CHIPS
Spot inline's betrayal: in inline mode the chips hug their text — the width: 130px is silently ignored, and so would height and vertical margins be. When a "why is my width doing nothing?!" afternoon strikes, check display first.
blockinlineinline-block
Row behaviourclaims the whole rowshares the lineshares the line
width / heightobeyedignoredobeyed
Default forp h1 div articlea strong span img*(opt-in only)
Classic usesections, cardswords inside sentencesnav pills, badge rows
GOING DEEPER — THE * ON img, AND THE TWO BIG SIBLINGS

<img> is technically inline but behaves like inline-block (it obeys width/height) — browsers special-case replaced elements. And the two display values this class deliberately defers: flex and grid, the modern layout engines. They arrive with the MERN project's real layouts later; block/inline/inline-block is the exam syllabus and the foundation both of them stand on.

ACTIVITY 3 · BROKEN-SITE DEBUGGING · ~8 MINUTES

The badge escaped its card. Nobody typed an error. Find the silent failure.

A classmate styled a NEW badge exactly like Part 6 taught — position: absolute; top: 8px; right: 8px; — and the badge flew to the top-right of the whole page, nowhere near its card. The CSS below is everything they wrote. No typos, no invalid lines: the browser executed it all happily. This is the classic silent CSS failure — the code is legal, the intent is broken.

badge-bug.html · plain HTML first, then the classmate's rules — legal, and wrongHTML BUILDS, THEN CSS — ONE PRESS PER LINE
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <title>Badge bug</title>
6</head>
7<body>
8 <article class="dish">
9 <h4>Ragi Idli Bowl — Rs. 50</h4>
10 <span class="badge">NEW</span> <!-- the escapee -->
11 </article>
12</body>
13</html>
·/* card + NEW badge on screen, plain. Now the classmate's <style> ↓ */
14<style> .dish { /* the card — but is it an ANCHOR? */
15 width: 300px; padding: 12px;
16 background-color: mintcream; border: 2px solid seagreen; }
17 .badge {
18 position: absolute; /* ...but there is NO positioned ancestor! */
19 top: 8px; right: 8px;
20 background-color: seagreen; color: white; } </style>
THE BROKEN RENDER — REAL
file:///C:/Users/student/Desktop/fswd-practice/class-11/badge-bug.html

Ragi Idli Bowl — Rs. 50

NEW
PLAIN HTML — NO <style> EXISTS YET ⚠ the badge just left the card and parked in the PAGE'S top-right corner
Your three diagnostic questions — answer in writing before unlocking.
DIAGNOSE IT
ANSWER
  • The badge measured its top: 8px; right: 8px from what — and why that box?
  • Which single line is missing, and from which rule?
  • Why did the browser show no error anywhere — DevTools console included?

This exact bug will find you in Lab 3. Diagnose it here, where it's cheap.

SOLUTION · ONE LINE, SIDE BY SIDE
BROKEN — NO ANCHOR
.dish { width: 300px; /* no position line — .dish is static */ } .badge { position: absolute; /* measures from the PAGE */ top: 8px; right: 8px; }
FIXED — CARD VOLUNTEERS AS FRAME
.dish { width: 300px; position: relative; /* THE FIX — one line */ } .badge { position: absolute; /* now measures from .dish */ top: 8px; right: 8px; }

The three verdicts: ① with no positioned ancestor anywhere, the badge climbed all the way up and measured from the page itself — absolute always walks up the family tree looking for a positioned parent and settles for the document if none volunteers. ② The missing line is position: relative on .dish — note the fix goes on the parent, not the element that looks wrong. ③ No error because nothing IS an error: every line is valid CSS doing exactly what it says. CSS never errors on legal-but-unintended — which is why the Part 3 DevTools habit, not the console, is how layout bugs get found.

Everything at once, on the real project

Poshtik's header — boxed, spaced and pinned, with today's whole toolkit.

One worked example, every idea from today: honest border-box sizing, deliberate padding instead of accidental gaps, inline-block nav pills that obey their width, and the header fixed to the top so the menu stays reachable while you scroll the ten dishes. Type it in the sandbox and watch each line land in the preview.

MINI PROBLEM · HEADER-PLAY.HTML
PROBLEM
Rebuild poshtik's page header as a professional fixed bar: dark coat, breathing room, pill nav — and prove the body needs a top offset so content doesn't hide underneath.
REQUIRE­MENTS
  • Header: background-color: darkslategray, padding: 12px 16px, position: fixed; top: 0; left: 0; right: 0;.
  • Nav links: display: inline-block, padding: 6px 14px, white text, no underline.
  • Body: padding-top: 70px — the fixed header floats OVER content; the body must duck under it.
  • Everything sized with box-sizing: border-box.
EXPECTED OUTPUT
A dark bar hugging the top of the window with two white pill links — and the page heading starting clearly below it, not hiding behind it. Scroll the preview: the bar stays.
header-play.html · complete file, from scratchBUILDS ONE PRESS AT A TIME
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <title>Header play</title>
6</head>
7<body>
8 <header><nav><a href="#">Menu</a><a href="#">About</a></nav></header>
9 <h1>Today's Healthy Ten</h1>
10</body>
11</html>
·/* HTML is complete & PLAIN above (a stacked nav, a heading). Now the <style> in <head> ↓ */
6 <style>
7 * { box-sizing: border-box; } /* honest widths, line one */
8 header { background-color: darkslategray; padding: 12px 16px; }
9 header { position: fixed; top: 0; left: 0; right: 0; } /* pinned */
10 nav a { display: inline-block; padding: 6px 14px; } /* share the row */
11 nav a { color: white; text-decoration: none; }
12 body { background-color: floralwhite; } /* h1 is HIDDEN under the bar! */
13 body { padding-top: 70px; } /* THE FIX — duck under the fixed bar */
14 </style>
REAL OUTPUT — PLAIN HTML FIRST, THEN EACH RULE, THEN SCROLL IT
file:///C:/Users/student/Desktop/fswd-practice/class-11/header-play.html
Poshtik Campus MenuAbout

Today's Healthy Ten

⚠ the heading is now UNDER the fixed bar — line 13 rescues it
Jonna Rotte Wrap — Rs. 60
Sorghum flatbread wrap with sprouts.
Ragi Idli Bowl — Rs. 50
Soft steamed finger-millet idlis.
Pesarattu — Rs. 45
Green-gram dosa, ginger chutney.
Ulava Charu Bowl — Rs. 70
Horse-gram protein bowl.

…scroll me — the dark bar never moves.

↑ PLAIN HTML — DEFAULT BLUE UNDERLINED LINKS, NO BAR, NO CARDS
The 70px duck-under is the step everyone forgets: a fixed header leaves the flow entirely — the body slides up underneath it. You just watched it happen at line 12 and get rescued at line 13. Delete line 13 in your own copy and the page title vanishes behind the bar. That one experiment is the whole lesson.
SAVE THIS AS
FOLDERC:\Users\student\Desktop\fswd-practice\class-11\
FILENAMEheader-play.html — one file: today's skeleton + the style block above
GIT?No — today's files are throwaway sandbox practice. The real repo's header gets this treatment during Lab 3's surgery, as one deliberate commit. Practice freely here; commit nothing.

Take it home

Your layout kit — the whole class on one card.

PROPERTYDECIDESTHE ONE THING TO REMEMBERTODAY'S EXAMPLE
paddingSpace INSIDE the border — same colour as the boxpushes content in; grows the visible boxpadding: 12px;
borderThe visible edge between inside and outsideit has thickness — it counts in the width sumborder: 2px solid seagreen;
marginSpace OUTSIDE — pushes the neighbours awaytransparent; vertical margins can collapsemargin: 0 auto; centres a box with a width
box-sizingWhat width meansborder-box = the honest total; line one of every pro stylesheet* { box-sizing: border-box; }
positionWHICH frame offsets measure fromabsolute hunts for a positioned parent — or takes the page.dish { position: relative; }
top / right / bottom / leftThe offsets themselvesdead lines on static — position must be set firsttop: 8px; right: 8px;
displayHow the box shares the rowinline IGNORES width/height; inline-block obeysnav a { display: inline-block; }
YOUR SANDBOX AFTER TODAY — THROWAWAY, ON PURPOSE
fswd-practice\class-11\
print-demo.html · the PYQ's screen-vs-print proof
header-play.html · fixed header + duck-under experiment
Nothing new lands in poshtik-campus\ today and nothing gets committed — today was X-ray training, not surgery. The real repo's header gets the fixed-bar treatment in Lab 3, as one deliberate commit, with today's knowledge behind it.

Class 11 · closed

You can see the boxes now. Next: making them fit every screen.

Today you earned X-ray vision — four layers on every element, the 328-pixel arithmetic, border-box honesty, the position playground and the display switcher — and you caught an escaped badge with a one-line fix on its parent. Class 12 asks the question every phone in this room is already asking: your 300px cards look right on the projector — what happens on a 360px screen? Media queries, the viewport, and responsive design close out CSS.

  • Five-minute drill: without notes, draw the four-layer diagram, label it, and compute the total width of a width: 200px; padding: 10px; border: 5px solid; margin: 20px box — both dialects: content-box and border-box.
  • PYQ rehearsal: write the P1·Q16a answer cold — the four layers half AND the screen-blue / paper-red media-type half with both magic phrases.
  • Ten-minute experiment: in header-play.html, delete the padding-top: 70px line, watch the title hide behind the bar, put it back. Then inspect the header in DevTools and read its real box.