View Full Version : element position
I am very surprised to see that I can not use offset postion to find the real position of an element:
<div id="myid" align="center">bla</div>
The alert shows 0...
I was expected that the element should show his offsetLeft relative to it's parent, which is body, but it does not... How the heck can I really find out the position of some element relative to the body? Generally speaking, to retreive the position relative to the body, nomatter the other container parents which that element might have?
Second surprise is that if I use a table instead of a div, the offset seems to work
<table width="400" border="0" align="center" cellpadding="2" cellspacing="2" id="myid">
That is really weird... hm:confused:
03-16-2005, 12:51 PM
Hi there kor,
it works with the table because you have given it a dimension. :)
This works with a div...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
oh... yea, stupid my oh my (despite Garfield, I hate Wednesdays :D ). I forgot that I have no width. Even I don't sense why I need the width, as long as the element position is the position of it's left/top corner... Well...
But a problem still occures... If I have a div inside another dimensioned parentNode, I expect that my div should have 100% of parent without mention that by all means.
So that to find out the real position of an element, the element and it's parents must have by all means dimensions?.
I wonder... Width is enough? Or I need the height...But table has the height of it's elements, nomatter the given value...
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.