W3C home > Mailing lists > Public > www-style@w3.org > March 2008

Re: [cssom-view] small update

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Thu, 20 Mar 2008 21:29:19 -0700
Message-ID: <c9e12660803202129u78529898w9c39e5affc4bd162@mail.gmail.com>
To: "Mike Wilson" <mikewse@hotmail.com>
Cc: Www-style <www-style@w3.org>

On Wed, Mar 19, 2008 at 4:07 AM, Mike Wilson <mikewse@hotmail.com> wrote:
> Hi Garrett,
>
>
>  > Aside from the bugs that occur in all FF/Op/Saf, there is a 1 clear,
>  > fundamental difference in the handling of offsetTop/Left when the
>  > offsetParent in question is BODY with position: relative.
>  <snip>
>
> > Insight:
>  >  For getting the position of an element: using offsetTop:
>  >  position: relative can be added to the container, BODY. This makes
>  > body work like a "normal" offsetParent in all browsers except Opera.
>
>  That's an interesting find! There are always more details to be
>  uncovered...

If browser vendors decide to implement offset* as per the CSSOM views
spec, it might introduce more complications to my position-finding
function.

>  So, it looks like Opera is the only browser today that is fully
>  compatible with CSOMM, others (representing ~99% of traffic) will have
>  to change.
>
>

Before the recent change to measure from element's outer edge to the
padding edge of the offsetParent, Opera was more closely compliant.
Previously, the measurement was to the border edge of the
offsetParent, which is what Opera 9 does.

>  > Position: relative on BODY is useful
>  > It use useful because makes BODY a containing block for absolutely
>  > positioned children; BODY margin affects absolutely positioned
>  > children.
>
>  I agree totally.
>
>
>  > Sad path:
>  > If the parentNode is BODY, then (even) if the parentNode has position:
>  > relative and el has position, then the function will return the
>  > distance between el and the edge of the document.
>  >
>  > This is how CSSOM defines it, and in reality, it is a problem
>  > in Opera.
>  >
>  > How should other browsers adopt this without breaking pages?
>
>  I agree with you, Garrett. In this case you want to deal with the BODY
>  margin separately from the positioned element's relation to its
>  offsetParent. It's two different decisions of the layout. It also
>  fits well with the Containing Block analogy for offsetParent and
>  offsetLeft/Top.
>

Most libraries turn a blind eye to the problem. YUI acknowledges it
and does not address it. From the YAHOO.Dom.getXY(el):-

/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */

-
 http://developer.yahoo.com/yui/examples/dom/getxy_clean.html
http://developer.yahoo.com/yui/examples/dom/getxy.html

In order to reliably determine the distance between two arbitrary
elements, BODY must have margin: 0.
By default, current browsers provide a default margin on BODY.
Having margin on BODY precludes the possibility of finding any
arbitrary element's distance from its offsetParent.
CSSOM defines offsetTop in a way that requires BODY to have margin 0
for measuring an element's position.
This is not fair to developers.

If the majority browser vendors change their implementation of
offsetParent, it could have adverse effects on millions of pages.

Should this really happen? And if it does, how is this a good thing?

Regards,

Garrett

>  Best regards
>  Mike
>
>
Received on Friday, 21 March 2008 04:29:53 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:55:02 GMT