Question

I have a div{position:absolute}. From w3cschools:

absolute - The element is positioned relative to its first positioned (not static) ancestor element

Is there an easy way with browser inspector(Chrome, Firebug) to get the first not static ancestor, to which my div was positioned relatively?

Was it helpful?

Solution

Works in Chrome, Safari, and Firefox:

  1. Right-click the <div> and choose 'Inspect Element'.
  2. In the inspector choose the "Console" tab and type in $0.offsetParent. Press enter.
  3. The result is the offset parent of your selected element.

Bonus: In Chrome and Safari, If you right-click the result in the console you can reveal it in the elements panel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top