Bug Tracker

Modify

Ticket #11110 (closed bug: cantfix)

Opened 17 months ago

Last modified 7 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 17 months ago by sindresorhus

  • Owner set to ryannaddy
  • Status changed from new to pending

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.

comment:2 Changed 17 months ago by ryannaddy

  • Status changed from pending to new

The example is as follows:

 http://jsfiddle.net/Stgdb/1/

Again, this works in Chrome/Firefox, but not Internet Explorer 9.

I noticed that in Internet Explorer 8 it works fine.

Last edited 17 months ago by ryannaddy (previous) (diff)

comment:3 Changed 16 months ago by mikesherov

  • Priority changed from undecided to high
  • Component changed from unfiled to offset

comment:4 Changed 16 months ago by mikesherov

  • Summary changed from Internet Explorer position left cacluations to Internet Explorer 9 reports incorrect left position when margin is "auto"

comment:5 Changed 16 months ago by mikesherov

  • Status changed from new to open
  • Milestone changed from None to 1.next

comment:6 Changed 15 months ago by gregc

Is there a workaround for this? I am also experiencing this issue and it's sort of a show stopper.

comment:7 Changed 11 months ago by mikesherov

  • Summary changed from Internet Explorer 9 reports incorrect left position when margin is "auto" to IE9 and Webkit reports incorrect left position when margin is "auto"

comment:8 Changed 7 months ago by timmywil

  • Owner changed from ryannaddy to petro
  • Status changed from open to assigned

comment:9 Changed 7 months ago by petro

  • Status changed from assigned to closed
  • Resolution set to cantfix
  • Summary changed from IE9 and Webkit reports incorrect left position when margin is "auto" to 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.