Opened 11 years ago
Closed 11 years ago
#11110 closed bug (cantfix)
Firefox reports incorrect left position when margin is "auto"
Reported by: | ryannaddy | Owned by: | petro |
---|---|---|---|
Priority: | high | Milestone: | 1.next |
Component: | offset | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Using the following code:
$(window).ready(function(){ var con = $("#container"); conP = con.position(); alert(conP.left); });
Internet explorer 9 displays an invalid left positioning, while chrome/Firefox displays it correctly.
The CSS is as follows:
#container{ width: 1000px; margin: auto; margin-top: 40px; box-shadow: 0 0 20px rgba(0,0,0,.7); }
Using the example above, in Chrome/Firefox the above alert box may display 150 while Internet Explorer displays 0.5
Change History (9)
comment:1 Changed 11 years ago by
Owner: | set to ryannaddy |
---|---|
Status: | new → pending |
comment:2 Changed 11 years ago by
Status: | pending → new |
---|
The example is as follows:
Again, this works in Chrome/Firefox, but not Internet Explorer 9.
I noticed that in Internet Explorer 8 it works fine.
comment:3 Changed 11 years ago by
Component: | unfiled → offset |
---|---|
Priority: | undecided → high |
comment:4 Changed 11 years ago by
Summary: | Internet Explorer position left cacluations → Internet Explorer 9 reports incorrect left position when margin is "auto" |
---|
comment:5 Changed 11 years ago by
Milestone: | None → 1.next |
---|---|
Status: | new → open |
comment:6 Changed 11 years ago by
Is there a workaround for this? I am also experiencing this issue and it's sort of a show stopper.
comment:7 Changed 11 years ago by
Summary: | Internet Explorer 9 reports incorrect left position when margin is "auto" → IE9 and Webkit reports incorrect left position when margin is "auto" |
---|
comment:8 Changed 11 years ago by
Owner: | changed from ryannaddy to petro |
---|---|
Status: | open → assigned |
comment:9 Changed 11 years ago by
Resolution: | → cantfix |
---|---|
Status: | assigned → closed |
Summary: | IE9 and Webkit reports incorrect left position when margin is "auto" → Firefox reports incorrect left position when margin is "auto" |
Actually, Webkit and IE9 are correct and Firefox is incorrect. position() should return the offset of the element relative to its nearest positioned ancestor, including the element's margins. Thus, the margins of the element shouldn't affect the returned position.
However, Firefox doesn't compute this offset correctly and as a result jQuery returns not only an incorrect position() but also an incorrect css("margin-left"). Compare the fiddle below in FF and Webkit/IE to see the difference: http://jsfiddle.net/mpetrovich/jRVXq/
This difference in behavior is ultimately caused by Firefox's version of window.getComputedStyle() which incorrectly returns 0px for margin-left when the declared margin is "auto": http://jsfiddle.net/mpetrovich/yvj9b/
There's an open issue with Mozilla to fix getComputedStyle() to match the spec (and Webkit/IE): https://bugzilla.mozilla.org/show_bug.cgi?id=381328
Since there isn't an efficient way to determine whether an element has margin: auto applied, this Firefox issue cannot be reliably caught and polyfilled. Thus, we're closing this issue as Can't Fix for now.
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.
Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.