W3C and style.left question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ivanhoe

    #1

    W3C and style.left question

    What I wanted was to get rid of offsetLeft and use "proper" way
    instead....but when I do
    document.getEle mentById('someD iv').style.left ;
    I keep getting empty string, unless I first set it manually (in CSS or js)
    to some value...

    if that is intended behavior(that is if I haven't f***d up something :) in
    my code), and there is no offsetLeft property in W3C recommendation, what is
    then "standard compliant" way to make browser calculate coordinates of some
    tag on the page???

    thanx in advance,
    ivan






  • Martin Honnen

    #2
    Re: W3C and style.left question



    ivanhoe wrote:
    [color=blue]
    > What I wanted was to get rid of offsetLeft and use "proper" way
    > instead....but when I do
    > document.getEle mentById('someD iv').style.left ;
    > I keep getting empty string, unless I first set it manually (in CSS or js)
    > to some value...
    >
    > if that is intended behavior(that is if I haven't f***d up something :) in
    > my code), and there is no offsetLeft property in W3C recommendation, what is
    > then "standard compliant" way to make browser calculate coordinates of some
    > tag on the page???[/color]

    If you don't set the CSS inline style with CSS (e.g
    <tag style="left: 100px;">
    ) or with script (e.g
    elementObject.s tyle.left = '100px';
    ) then it is correct that element.style.l eft returns an empty string as
    element.style.c ssProperty is not a cascaded computed CSS value but
    simply a reflection of the inline style set on an element.
    If you want a computed CSS value then with Netscape 6/7, Mozilla and
    with Opera 7 you have DOM Level 2 support for
    window.getCompu tedStyle(elemen t, '').getProperty Value('left')
    however what browsers implement as offsetLeft follows different rules
    compared to what getComputedStyl e does so if your application works well
    across browsers reading offsetLeft on abritrary elements you should in
    my view stick with that. Or if you want to use getComputedStyl e make
    sure you test for your elements whether there are differences to
    offsetLeft and adapt your script expressions if needed.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • DU

      #3
      Re: W3C and style.left question

      ivanhoe wrote:
      [color=blue]
      > What I wanted was to get rid of offsetLeft and use "proper" way
      > instead....but when I do
      > document.getEle mentById('someD iv').style.left ;
      > I keep getting empty string, unless I first set it manually (in CSS or js)
      > to some value...
      >[/color]

      The css position property value defaults to static; it must be set to
      relative or absolute or fixed, otherwise setting
      ElemRef.style.l eft
      to some value does not make any sense.
      [color=blue]
      > if that is intended behavior(that is if I haven't f***d up something :) in
      > my code), and there is no offsetLeft property in W3C recommendation,[/color]

      True, there is no offsetLeft property in W3C recommendation. I think W3C
      should have adopted the MSIE's DHTML object model. offset* values are
      often very useful.

      what is[color=blue]
      > then "standard compliant" way to make browser calculate coordinates of some
      > tag on the page???
      >
      > thanx in advance,
      > ivan
      >
      >[/color]

      The coordinates you're referring to must be relative to some point of
      reference. offset* values are relative to offsetParent element: that's
      per definition. offsetParent is not part of the DOM Core. left, top,
      bottom, right css properties (for abs. pos. elements) are relative to
      the closest containing positioned element within the containment
      hierarchy. There is a sharp distinction between the 2.

      Interactive demo page on CSS positioning


      DU

      Comment

      Working...