0
0
CSSmarkup~20 mins

Stacking context in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stacking Context Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What creates a new stacking context?
Which CSS property value combination creates a new stacking context for an element?
Aposition: relative; z-index: auto;
Bopacity: 1;
Cdisplay: block;
Dposition: absolute; z-index: 0;
Attempts:
2 left
💡 Hint
Think about when z-index actually creates a stacking context.
📝 Syntax
intermediate
2:00remaining
Which CSS snippet correctly creates a stacking context?
Select the CSS snippet that correctly creates a stacking context on an element.
Adiv { display: flex; }
Bdiv { opacity: 1; }
Cdiv { position: fixed; z-index: 10; }
Ddiv { position: static; z-index: 5; }
Attempts:
2 left
💡 Hint
Remember that position must not be static for z-index to create stacking context.
rendering
advanced
3:00remaining
Visual stacking order with nested stacking contexts
Given the following HTML and CSS, which element will appear on top visually?
CSS
HTML:
<div class="parent">
  <div class="child1">Child 1</div>
  <div class="child2">Child 2</div>
</div>

CSS:
.parent {
  position: relative;
  z-index: 1;
  background: lightblue;
  width: 200px;
  height: 200px;
}
.child1 {
  position: relative;
  z-index: 2;
  background: coral;
  width: 100px;
  height: 100px;
  margin: 20px;
}
.child2 {
  position: relative;
  z-index: 1;
  background: lightgreen;
  width: 100px;
  height: 100px;
  margin: 50px;
}
AChild 1 appears on top of Child 2
BChild 2 appears on top of Child 1
CBoth children appear at the same level, overlapping equally
DParent appears on top of both children
Attempts:
2 left
💡 Hint
Look at the z-index values and stacking contexts of parent and children.
selector
advanced
2:00remaining
Which CSS selector targets elements creating stacking contexts?
Which CSS selector matches elements that create a stacking context due to opacity less than 1 (e.g., opacity: 0.99)?
A*[style*="opacity:"]
B*[style*="opacity: 0.99"]
C*[style*="opacity: 0.5"]
D*[style*="opacity: 0"]
Attempts:
2 left
💡 Hint
Stacking context is created when opacity is less than 1.
accessibility
expert
3:00remaining
How does stacking context affect keyboard navigation?
Which statement best describes how stacking context can impact keyboard navigation and accessibility?
AStacking context does not affect keyboard navigation order but can affect visual focus indication.
BElements in higher stacking contexts are always focused first when tabbing.
CElements with lower z-index are skipped by screen readers.
DKeyboard navigation order is determined by z-index values.
Attempts:
2 left
💡 Hint
Think about how keyboard focus moves and what stacking context controls.