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
- What is the default position value? (A) static (B) absolute (C) fixed (D) sticky. Answer: A. Elements use static positioning by default.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.