spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / diner / realpos1

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Determining Element Page Coordinates, Part 1
IE for Windows, NS6

Positioned Elements

Positioned elements, as we know, store their x-y coordinates in the

  • elementReference.left      (W3C standard. IE and NS6+)
  • elementReference.pixelLeft (non-standard. IE only)
  • elementReference.posLeft   (non-standard. IE only)
properties of their style object. These read/write properties, however, reflect the distance of the element from the containing element. A top-level positioned element is contained within the

element, synonymous with the window object for the purpose of determining position. The above properties will, therefore, give us the page position of the element if it is a top-level positioned element. If the positioned element is nested within another positioned element, the above properties return the position of the nested element within the parent element, not the page position.

All positioned elements define the beginning of a new coordinate system. The position properties of all contained elements reflect the distance of the elements from the top-left of the containing element.

Regular (Static) HTML Elements

All HTML elements, positioned or not, have two read-only properties that reflect position:

  • elementReference.offsetLeft
  • elementReference.offsetTop (both non-standard. IE and NS6+)

All HTML elements also have properties that store the types of parent elements that every element has:

  • elementReference.parentElement (non-standard. IE only)
  • elementReference.parentNode    (standard. IE5+ and NS6+)
  • elementReference.offsetParent  (non-standard. IE and NS6+)

An element is nested within its parentElement or parentNode.
An element is offset (positioned) within its offsetParent.

Consider this snippet of HTML:

<TABLE>
  <TR>
    <TD>
      <P>
        <B>
          <I ID="BoldItalicElement">I am bold-italic text</I>
        </B>
      </P>
    </TD>
  </TR>
</TABLE>

The BoldItalicElement element (<I>) is nested within the <B> element.
The BoldItalicElement element (<I>) is offset (positioned) within the <TD> element.

The parentElement of BoldItalicElement is the <B> element.
The parentNode of BoldItalicElement is the <B> element.
The offsetParent of BoldItalicElement is the <TD> element in IE.
The offsetParent of BoldItalicElement is the <BODY> element in NS6 non-standards mode.
The offsetParent of BoldItalicElement is the <HTML> element in NS6 standards mode.

As you can see, there are regular HTML elements that act like positioned elements in defining new coordinate systems.

In IE, TABLE and TD are two of these. The reason should be immediately apparent. Their content is offset within them, and is not part of the normal flow of the document. On the other hand, P, B, I, et al. do not affect positioning, just content display.

In NS6+, what is considered an offset parent depends on the browser version used. There are three different variations. These are discussed later.

The parentElement, the parentNode and the offsetParent may be the same element, depending on your page layout. The offsetParent property should be used, however, when determining position.

But, we are getting ahead of ourselves here.

Before we begin to discuss position deduction, we must view it in context. It would be highly beneficial to examine the different approaches to document hierarchy in detail first.



Produced by Peter Belesis and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

All Rights Reserved. Legal Notices.
Created: May 18, 1998
Revised: August 26, 2002

URL: http://www.webreference.com/dhtml/diner/realpos1/2.html