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 is a stacking context in CSS?
A stacking context is like a special group in CSS where elements are stacked in order. Elements inside this group stack above or below each other without mixing with elements outside the group.
Click to reveal answer
beginner
Name one CSS property that creates a new stacking context.
The position property with values relative, absolute, or fixed combined with a z-index value other than auto creates a new stacking context.
Click to reveal answer
beginner
How does the z-index property relate to stacking contexts?
z-index controls the order of elements inside a stacking context. Higher z-index means the element appears on top within that context.
Click to reveal answer
intermediate
True or False: Elements from different stacking contexts can overlap based on their z-index values alone.
False. Elements in different stacking contexts stack independently. Their z-index values only affect order inside their own context, not across contexts.
Click to reveal answer
intermediate
What happens visually when a new stacking context is created?
Visually, the new stacking context acts like a separate layer. Elements inside it stack among themselves, but the whole group stacks as one unit with other elements outside.
Click to reveal answer
Which CSS property combination creates a new stacking context?
Acolor: red;
Bfont-size: 16px;
Cmargin: 10px;
Dposition: relative; z-index: 1;
✗ Incorrect
Only 'position: relative' with a 'z-index' value other than 'auto' creates a new stacking context.
Inside a stacking context, which element appears on top?
AElement with the lowest z-index
BElement with the highest z-index
CElement that appears first in HTML
DElement with the largest size
✗ Incorrect
Within a stacking context, elements with higher z-index values appear on top.
True or False: z-index values affect stacking order across different stacking contexts.
AFalse
BTrue
COnly if z-index is greater than 10
DOnly for fixed position elements
✗ Incorrect
z-index only controls stacking order inside the same stacking context, not across different ones.
Which of these CSS properties does NOT create a stacking context by itself?
Abackground-color
Btransform with any value
Cposition: fixed
Dopacity less than 1
✗ Incorrect
Background color alone does not create a stacking context.
What is the visual effect of stacking contexts on overlapping elements?
AStacking contexts have no effect on overlap
BElements from different contexts mix freely based on z-index
CEach stacking context stacks its elements independently
DElements with lower opacity always appear on top
✗ Incorrect
Each stacking context stacks its elements independently, acting like separate layers.
Explain what a stacking context is and why it matters in CSS layout.
Think about how layers stack in real life, like papers on a desk.
You got /4 concepts.
List common CSS properties or conditions that create a new stacking context.
Remember properties that change how browsers group elements visually.
You got /5 concepts.
Practice
(1/5)
1. What creates a new stacking context in CSS?
easy
A. An element with color property set
B. An element with position: relative and z-index set
C. Any element with display: block
D. An element with margin applied
Solution
Step 1: Understand stacking context creation
A stacking context is created by elements with position other than static and a z-index value set.
Step 2: Analyze options
Only An element with position: relative and z-index set mentions position: relative with z-index, which creates a stacking context. Other options do not create stacking contexts.
Final Answer:
An element with position: relative and z-index set -> Option B
Quick Check:
Stacking context = position + z-index [OK]
Hint: Look for position plus z-index to spot stacking contexts [OK]
Common Mistakes:
Thinking any positioned element creates stacking context without z-index
Confusing display or color properties with stacking context
Assuming margin affects stacking order
2. Which CSS snippet correctly creates a stacking context?
easy
A. position: static; z-index: 10;
B. display: inline; z-index: 3;
C. position: relative; z-index: 5;
D. color: red; z-index: 1;
Solution
Step 1: Check position and z-index combination
Only elements with position other than static and a z-index value create stacking contexts.
Step 2: Evaluate each option
position: relative; z-index: 5; uses position: relative and z-index: 5, which correctly creates a stacking context. Others either have static position or irrelevant properties.
Final Answer:
position: relative; z-index: 5; -> Option C
Quick Check:
Position relative + z-index creates stacking context [OK]
Hint: Position must not be static to create stacking context [OK]
Common Mistakes:
Using position static with z-index expecting stacking context
Assuming display or color create stacking contexts
Ignoring that inline elements don't create stacking contexts with z-index
3. Given this HTML and CSS, which element appears on top visually?
Which statement is true about their stacking order?
hard
A. Inner's z-index 10 stacks only inside outer's stacking context
B. Inner's z-index 10 places it above all elements outside outer
C. Outer and inner share the same stacking context ignoring z-index
D. Inner's z-index is ignored because outer has lower z-index
Solution
Step 1: Identify stacking contexts
The outer element creates a stacking context with position: relative and z-index: 1. The inner element creates a new stacking context inside outer with position: relative and z-index: 10.
Step 2: Understand stacking context isolation
Inner's stacking order is only relative to siblings inside outer's stacking context. It cannot escape outer's stacking context to appear above elements outside it.
Final Answer:
Inner's z-index 10 stacks only inside outer's stacking context -> Option A