Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the CSS z-index property control?
The z-index property controls the stack order of elements along the z-axis (front to back). Higher values appear on top of lower values.
Click to reveal answer
intermediate
What is a stacking context in CSS?
A stacking context is a group of elements that share the same stacking order rules. It acts like a mini-layer system inside the page, isolating elements from others outside it.
Click to reveal answer
intermediate
Why might an element with a higher z-index appear behind another element?
Because it might be inside a different stacking context with a lower parent z-index, or the element's position property is not set to create stacking context properly.
Click to reveal answer
beginner
How does the CSS position property affect layering?
Only elements with position set to relative, absolute, fixed, or sticky can have a z-index that affects layering.
Click to reveal answer
beginner
What common mistake causes layering issues with dropdown menus or modals?
Not setting position and z-index properly on dropdowns or modals, or having parent containers with overflow: hidden that clip the element.
Click to reveal answer
Which CSS property must be set for z-index to work?
Apadding
Bposition
Cmargin
Ddisplay
✗ Incorrect
The position property must be set to relative, absolute, fixed, or sticky for z-index to take effect.
What is a stacking context?
AA group of elements with shared layering rules
BA CSS property for colors
CA type of HTML tag
DA JavaScript function
✗ Incorrect
A stacking context is a set of elements that follow the same layering rules, isolating their z-index from elements outside.
Why might a dropdown menu be hidden behind other content?
AThe menu has no text
BThe menu uses <code>display: block</code>
CParent container has <code>overflow: hidden</code>
DThe page has no CSS
✗ Incorrect
When a parent container has overflow: hidden, it can clip child elements like dropdowns, hiding them behind other content.
Which z-index value appears on top?
A-1
B5
C0
D10
✗ Incorrect
Higher z-index values appear on top of lower ones.
If two elements have the same z-index, which one appears on top?
AThe one later in the HTML code
BThe one earlier in the HTML code
CThe one with smaller font size
DThe one with more padding
✗ Incorrect
When z-index is equal, the element that comes later in the HTML code appears on top.
Explain what causes layering issues in CSS and how stacking contexts affect element visibility.
Think about how elements are grouped and ordered in layers.
You got /5 concepts.
Describe how to fix a dropdown menu that appears behind other page content.
Consider both the dropdown and its container styles.
You got /4 concepts.
Practice
(1/5)
1. Which CSS property controls the stacking order of elements on a webpage?
easy
A. float
B. position
C. z-index
D. display
Solution
Step 1: Understand stacking order control
The z-index property sets which element appears on top when elements overlap.
Step 2: Differentiate from other properties
position sets how elements are positioned but does not control layering alone; display and float affect layout, not stacking order.
How can you make #b appear on top without changing its z-index value?
hard
A. Change #b's position to relative and keep z-index 1
B. Wrap #b in a parent with higher z-index and position set
C. Set #a and #c to position: static
D. Increase #b's width and height
Solution
Step 1: Understand stacking context
Elements create stacking contexts based on position and z-index. #b has z-index 1 but is inside its own stacking context.
Step 2: Use parent stacking context to raise #b
Wrapping #b in a parent with a higher z-index and position creates a new stacking context that can appear above #a and #c without changing #b's z-index.
Final Answer:
Wrap #b in a positioned parent with higher z-index -> Option B
Quick Check:
Use parent stacking context to control layering [OK]
Hint: Use parent with higher z-index to raise child layering [OK]