Nested absolutely positioned elements can exhibit unexpected behavior in CSS. Consider this scenario:
Q: Why is #3rd absolutely positioned relative to #2nd instead of #1st?
A: Because position: absolute within an absolutely positioned element resets the relative position for its children.
This property effectively overrides the relative positioning of #1st for #3rd, making it position absolute relative to its direct parent, #2nd.
To achieve your desired behavior, where #3rd is absolutely positioned relative to #1st, you would need to make #3rd a direct child of #1st.
The above is the detailed content of Why Does Nested Absolute Positioning Cause Elements to Refer to Their Parent Instead of the Grandparent?. For more information, please follow other related articles on the PHP Chinese website!