Cross browser (chrome/firefox) trying to get top-pos defined in percentage as pixels

Posted by Cinaird on Stack Overflow See other posts from Stack Overflow or by Cinaird
Published on 2010-04-18T09:52:22Z Indexed on 2010/04/18 9:53 UTC
Read the original article Hit count: 289

Filed under:
|
|
|
|

I have a problem whit cross browser output, I'm trying to get the top and left css attribute of a div, but firefox gives me the exact pixel position and Chrome give me the percentage.

Example: http://web.cinaird.se/pdf/test.htm

CSS

#mix{
    position:absolute;
    top: 10px;
    left: 45%;
    background-color:#f0f;
}

jQuery

css top: " + $("#mix").css("top") + " <br/>css left: " + $("#mix").css("left")

Output

Firefox (and IE8): css top: 10px css left: 267.3px

Chrome: css top: 10px css left: 45%

is there any way to get the same result for both (all) browsers? I would prefer to get a pixel value without any major calculation

© Stack Overflow or respective owner

Related posts about google-chrome

Related posts about div