HTML & CSS · Senior · Question 12 of 75
What happens to a position: fixed element if an ancestor has transform: translateZ(0)?
- 1Nothing:
fixedis always positioned relative to the browser window - ✓Correct answer: It becomes positioned relative to that ancestor
- 3The element stops rendering while the ancestor has a
transform
Explanation
An ancestor with transform, filter, perspective, contain: paint or will-change: transform becomes the containing block for fixed descendants. A modal inside an animated container suddenly "sticks" to the container instead of the window. That's why modals and toasts are rendered through a portal at body level.