Reputation: 5613
I'm calling getComputedStyle on an element that defines left
, right
and bottom
.
In Chrome this returns 'auto'
as the value for top
but in Firefox this returns the pixel value, however if you look at the inspector in Firefox the top
value doesn't show up in the computed pane.
Is there any way to workaround this? Here is a fiddle showing the issue http://jsfiddle.net/DEfusion/9NaGD/
Upvotes: 3
Views: 865
Reputation: 83
Old question, but I came across this problem too and got the solution, as Prisoner said, Firefox does things a little differently as for some properties, it will return the used value (it will transform auto to pixels) instead of the resolved value. Fortunately since Firefox 19 there's a solution called getDefaultComputedStyle, supported only in firefox and returning the resolved values.
One way to do it would then be to test for the browser, use getDefaultComputedStyle if Firefox, else use getComputedStyle
Upvotes: 1
Reputation: 27618
Via: https://developer.mozilla.org/en/docs/Web/API/window.getComputedStyle
In Firefox, properties with the value auto return the used value, not the value auto. So if you apply top:auto; and bottom:0; on an element with height:30px and its containing block is height:100px;, upon requesting the computed style for top, Firefox will return top:70px, as 100px-30px=70px.
Upvotes: 1