0

For instance, I have a div, with a margin of, say, 20%, and I want to find the distance between [the left side of] it and [the left side of] the body. Is there a way of doing this that supports all major browsers and is guaranteed to work for at least the latest versions (eg. ie 7+, safari 3+, firefox (whatever they're up to now)+, etc.), and is possibly contained inside of other elements?

<!DOCTYPE html>
<html>
    <head>
        <!--stuff that goes here-->
    </head>
    <body>
        <div id="outer">
            <div id="calculateDistance">et cetera
            </div>
        </div>
    </body>
</html>

and the css

#outer{
    margin:10%;
    padding:5%;
    border:1px solid #000000;
}
#calculateDistance{
    margin:20%
    border:3em solid #000000;
}
Doge
  • 347
  • 1
  • 4
  • 13
  • 1
    Which is the left side, exactly? Do you want to include padding, border, margin? – Oriol Jul 09 '14 at 14:34
  • if it needs to be pure js, [this may help](http://stackoverflow.com/questions/288699/get-the-position-of-a-div-span-tag), otherwise try [this jquery](http://api.jquery.com/offset/) – Pete Jul 09 '14 at 14:44
  • Yes it needs to be pure js, I want to include everything that will push it away from the side. I'll give that link a try tomorrow morning when I'm at my PC – Doge Jul 09 '14 at 15:01
  • "Latest versions" and you include IE7? !! – Paulie_D Jul 09 '14 at 15:09
  • The thing I'm working on ATM is *somewhat* IE7 compatible. – Doge Jul 10 '14 at 01:44

0 Answers0