MCQ Hive stays free thanks to ads. Please disable your ad blocker for this site so content and features keep working.
Web Development
CSS
Beginner
Q
What is an element with position: absolute positioned relative to?
AAlways the viewport
BIts original place in the normal flow
CAlways its parent element
DIts nearest ancestor whose position is not static
Correct Answer:
D. Its nearest ancestor whose position is not static
Explanation:
If no such ancestor exists, it is positioned relative to the initial containing block.
ALSO KNOW (related points):
• What is the difference between display: none and visibility: hidden? → display: none removes the element from the layout; visibility: hidden hides it but keeps its space
• Why might z-index: 999 have no effect on an element? → z-index applies only to positioned elements (and flex or grid items); a static element ignores it
• What does position: sticky do? → The element acts as relatively positioned until a scroll threshold is reached, then sticks like a fixed element within its container