0
0
CSSmarkup~20 mins

Z-index basics in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Z-index Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the stacking order of these elements?

Consider three overlapping boxes with the following CSS:

  .box1 { position: relative; z-index: 2; }
  .box2 { position: relative; z-index: 5; }
  .box3 { position: relative; z-index: 1; }

Which box will appear on top?

Abox2 will be on top
Bbox1 will be on top
Cbox3 will be on top
DAll boxes will have the same stacking order
Attempts:
2 left
💡 Hint

Higher z-index means the element is closer to the viewer.

🧠 Conceptual
intermediate
2:00remaining
What happens if z-index is set on a static element?

Given an element with position: static; and z-index: 10;, what will happen?

AThe element will be stacked above others with lower z-index
BThe element will become positioned automatically
CThe element will disappear from the page
DThe z-index will be ignored because position is static
Attempts:
2 left
💡 Hint

z-index only works on positioned elements (relative, absolute, fixed, sticky).

📝 Syntax
advanced
2:00remaining
Identify the invalid z-index value

Which of the following CSS z-index values is invalid?

Az-index: 1.5;
Bz-index: -1;
Cz-index: auto;
Dz-index: 100;
Attempts:
2 left
💡 Hint

z-index accepts integers or 'auto', but not decimals.

optimization
advanced
2:00remaining
How to simplify stacking context for better performance?

You have many nested elements with different z-index values creating complex stacking contexts. What is the best way to optimize rendering performance?

AIncrease all z-index values to very high numbers
BUse fewer positioned elements and avoid unnecessary z-index values
CUse only static positioning and no z-index
DAdd z-index to every element regardless of position
Attempts:
2 left
💡 Hint

Complex stacking contexts can slow down rendering.

🔧 Debug
expert
3:00remaining
Why does this element not appear above another despite higher z-index?

Given these CSS rules:

.parent { position: relative; z-index: 1; }
.child1 { position: absolute; z-index: 10; }
.child2 { position: absolute; z-index: 5; }
.sibling { position: relative; z-index: 2; }

Why might .child1 not appear above .sibling even though it has a higher z-index?

A<code>.child1</code> z-index is ignored because it is absolutely positioned
B<code>.sibling</code> has a higher z-index than <code>.child1</code> so it appears on top
C<code>.child1</code> is inside <code>.parent</code> which has lower z-index than <code>.sibling</code>, so stacking context limits it
DThe browser ignores z-index when elements overlap
Attempts:
2 left
💡 Hint

Stacking contexts are created by positioned elements with z-index.