469,286 Members | 2,419 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Absolute coordinates on a relatively positioned element?


This must be an ancient question but I defy you to find a way to
search for it.

If I have a div:

<div style="position:relative;">wefwe</div>

And it's nested deep with in the html on my page, how do I find it's
absolute left and top (x and y) coordinates?

Jun 20 '07 #1
3 4477
dt******@hotmail.com wrote:
This must be an ancient question but I defy you to find a way to
search for it.

If I have a div:

<div style="position:relative;">wefwe</div>

And it's nested deep with in the html on my page, how do I find it's
absolute left and top (x and y) coordinates?
You need to search through the hierarchy of offsetParents. This is more
of a javascript question than a CSS question, but I'll point you in the
right direction:

http://www.quirksmode.org/js/findpos.html

Jeremy
Jun 21 '07 #2
On Jun 20, 8:00 pm, Jeremy <jer...@pinacol.comwrote:
dterr...@hotmail.com wrote:
This must be an ancient question but I defy you to find a way to
search for it.
If I have a div:
<div style="position:relative;">wefwe</div>
And it's nested deep with in the html on my page, how do I find it's
absolute left and top (x and y) coordinates?

You need to search through the hierarchy of offsetParents. This is more
of a javascript question than a CSS question, but I'll point you in the
right direction:

http://www.quirksmode.org/js/findpos.html

Jeremy

Thanks, perfect. In fairness, I didn't know it was a javascript
question. There could have been like a ".absoluteLeft" property that
I didn't know about. (In fact that would seem more likely, there
really SHOULD be such a property.)
Jun 22 '07 #3
On Jun 22, 10:14 am, dterr...@hotmail.com wrote:
You need to search through the hierarchy of offsetParents. This is more
of a javascript question than a CSS question, but I'll point you in the
right direction:
For modern browsers there are simpler alternatives than walking the
inheritance tree. This is one thread that discusses using
window.getComputedStyle to get the full set of css properties whether
explictly set or not. It also gives you the absolute position on the
page.
http://groups.google.com/group/comp....955e390e0c5173
Jun 24 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ken Kast | last post: by
14 posts views Thread by Harlan Messinger | last post: by
4 posts views Thread by louissan | last post: by
4 posts views Thread by Robert | last post: by
4 posts views Thread by mike eli | last post: by
2 posts views Thread by Rob R. Ainscough | last post: by
reply views Thread by Microsoft Newsserver | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.