CSS Module 9
Normal flow, positioning and stacking interview questions
Interview questions on normal flow, positioning and stacking: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher
What is the difference between position: absolute and position: fixed?
Answered in the lesson Positioning: relative, absolute, fixed and sticky
-
Fresher
What is a stacking context, and why can a z-index of 9999 still lose?
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
A fixed chat button worked until a teammate added a page-load animation to the main wrapper. Now the button scrolls away with the page in every browser. Explain why, and give three fixes with their trade-offs.
- What it tests
- Containing blocks of fixed boxes, which properties capture them, animation fill modes, and choosing between a CSS, a markup and a top-layer fix.
- First step
- Read the wrapper's computed transform once the animation has ended. With animation-fill-mode: both it stays at the last frame, matrix(1, 0, 0, 1, 0, 0), an identity transform, and any transform other than none makes the wrapper the containing block of its fixed descendants. The button is now fixed to the wrapper, not the viewport.
- Follow-ups
-
- Which other properties cause the same bug?
- How would you find the culprit on a large page?
- Does making the button a popover fix it, and what else changes?
From the lesson Positioning: relative, absolute, fixed and sticky
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A documentation site has a 64 px sticky header and a sticky sidebar in a flex layout. Users report that the sidebar scrolls away, and an accessibility audit fails WCAG 2.2 success criterion 2.4.11. Diagnose both problems and fix them.
- What it tests
- Sticky positioning inside flex layout, how browsers scroll focus into view, scroll-padding, and what Focus Not Obscured (Minimum) requires.
- First step
- Treat them as two bugs. The sidebar is a flex item, stretched to the full height of its row, so its containing block leaves it no room to move. The audit failure is focus: the browser scrolls a focused link only when it is outside the viewport, so a link that sits under the 64 px header counts as visible and stays hidden.
- Follow-ups
-
- How would you test the focus fix automatically?
- The header shrinks to 48 px once the page scrolls. What changes?
- Do links to #fragments on the page have the same problem?
From the lesson Positioning: relative, absolute, fixed and sticky
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
Product cards have position: relative and z-index: 1 so their hover shadow overlaps their neighbours. Since someone added will-change: opacity to the header for a smoother fade-in, the header's dropdown, z-index: 9999, opens under the cards. Explain why with the painting order, and give two fixes.
- What it tests
- Which properties create stacking contexts, how sibling contexts are compared, and choosing between raising a context, removing one and using the top layer.
- First step
- Look at the header, not the menu. will-change: opacity makes the header a stacking context at all times, at level 0, so the menu's 9999 now counts only inside it. Each card is a context at level 1 in the same parent context, and level 1 is painted after level 0, whole header and menu included.
- Follow-ups
-
- Why did the bug only appear after will-change was added?
- Would z-index: 2147483647 on the menu ever help?
- How would you stop this kind of bug across the whole site?
From the lesson Stacking contexts and z-index
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
You inherit a stylesheet with 47 different z-index values, from -1 to 2147483647, and every release brings a new layering bug. Design the system that replaces it, and explain how you would migrate without breaking pages.
- What it tests
- Turning stacking contexts into an architecture: a named scale, isolated components, the top layer for overlays, and a migration that is checked rather than hoped for.
- First step
- Take an inventory before changing anything. Group the 47 values by what they are for: page layers such as the sticky header, overlays such as dialogs and toasts, and values inside components. Each group has a different replacement. Then record which box is on top at the important points of the important pages, so every change can be checked.
- Follow-ups
-
- Which layers move to the top layer, and what changes for them?
- How do you keep the z-index values inside components from leaking?
- How do you prove that nothing changed during the migration?
From the lesson Stacking contexts and z-index
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes