I'll try to explain what i'm trying to get. I've a div with position:fixed (at the bottom of a page) into that div, there is some other divs. What i want is to show another div (with absolute position) aligned to the right with those divs... in other words, i wan't to know the left position of the divs...
Clearly, nothing can be absolute and relative at the same time. Either you want the element to position itself based on another ancestor's position or based on the page flow.
jQuery position() MethodThe position() method returns the position (relative to its parent element) of the first matched element. This method returns an object with 2 properties; the top and left positions in pixels.
First set position of the parent DIV to relative (specifying the offset, i.e. left , top etc. is not necessary) and then apply position: absolute to the child DIV with the offset you want. It's simple and should do the trick well.
If you specify position:relative, then you can use top or bottom, and left or right to move the element relative to where it would normally occur in the document. Position Absolute: When you specify position:absolute, the element is removed from the document and placed exactly where you tell it to go.
Relative to the document:
$('#ID').offset().left
Relative to its offset parent:
$('#ID').position().left
$('#ID').position().left
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With