Skip to content

Courses / CSS3 Mastery: Beginner to Advanced / Display, Positioning, Stacking Contexts and Z-Index

2,092 people viewed this

Display, Positioning, Stacking Contexts and Z-Index

Inset sets top, right, bottom and left offsets. A single zero fills the containing block when the other sizing conditions permit.

Practice Exercise

Create a card with a positioned badge, a fixed support button, a sticky header and a modal overlay. Experiment with z-index and opacity-created stacking contexts.

Quiz — 10 MCQs

  1. What is the default position value? (A) static (B) absolute (C) fixed (D) sticky. Answer: A. Elements use static positioning by default.
  2. Which positioning removes an element from normal flow? (A) absolute (B) static (C) relative (D) ordinary block. Answer: A. Absolute positioning removes the element's box from normal flow.
  3. Does relative positioning normally preserve the original layout space? (A) Yes (B) No (C) Only with Grid (D) Only for images. Answer: A. Relative offsets do not remove the element from flow.
  4. What does position: fixed commonly reference? (A) Viewport (B) Previous sibling (C) Font size (D) Database. Answer: A. Fixed positioning commonly uses the viewport unless another containing block is established.
  5. What does sticky positioning require to stick in a direction? (A) An appropriate inset threshold (B) An ID selector (C) A border always (D) A JavaScript framework. Answer: A. An inset such as top: 0 establishes the threshold.
  6. What does z-index affect? (A) Stacking order where applicable (B) Font family (C) Text spelling (D) Database order. Answer: A. It influences stacking within relevant stacking contexts.
  7. Can a child with z-index: 9999 always escape its parent's stacking context? (A) Yes (B) No (C) Only on mobile (D) Only with flex. Answer: B. A child is constrained by its ancestor stacking context.
  8. Which value commonly creates a stacking context? (A) opacity: 0.5 (B) color: blue (C) margin: 10px (D) font-size: 18px. Answer: A. Opacity below 1 creates a stacking context.
  9. What is inline-block useful for? (A) Inline participation with box dimensions (B) Removing all content (C) Making an element fixed (D) Loading fonts. Answer: A. It combines inline participation with a dimensionable box.
  10. What can interfere with sticky positioning? (A) Ancestor scrolling and overflow behavior (B) The HTML title only (C) Text color only (D) A comment. Answer: A. Sticky behavior depends on scrolling containers and available layout space.

Key Takeaways

  • Display controls formatting behavior.
  • Positioning determines normal-flow participation and offsets.
  • Z-index must be understood together with stacking contexts.

Rate this course

No ratings yet — yours can be the first.

Stars show on this course. Your written note stays private.

Your stars