Absolute coordinates on a relatively positioned element?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dterrors@hotmail.com

    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;">wef we</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?

  • Jeremy

    #2
    Re: Absolute coordinates on a relatively positioned element?

    dterrors@hotmai l.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;">wef we</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:



    Jeremy

    Comment

    • dterrors@hotmail.com

      #3
      Re: Absolute coordinates on a relatively positioned element?

      On Jun 20, 8:00 pm, Jeremy <jer...@pinacol .comwrote:
      dterr...@hotmai l.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;">wef we</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:
      >

      >
      Jeremy

      Thanks, perfect. In fairness, I didn't know it was a javascript
      question. There could have been like a ".absoluteL eft" property that
      I didn't know about. (In fact that would seem more likely, there
      really SHOULD be such a property.)


      Comment

      • tagbert

        #4
        Re: Absolute coordinates on a relatively positioned element?

        On Jun 22, 10:14 am, dterr...@hotmai l.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.getCompu tedStyle to get the full set of css properties whether
        explictly set or not. It also gives you the absolute position on the
        page.



        Comment

        Working...