Skip to main content

Bug Tracker

Side navigation

#3333 closed bug (fixed)

Opened September 05, 2008 03:25PM UTC

Closed March 24, 2011 10:58PM UTC

Last modified April 12, 2012 11:28AM UTC

.css("marginRight") is incorrect in WebKit

Reported by: soldair Owned by: rworth
Priority: blocker Milestone: 1.5.2
Component: dimensions Version: 1.5
Keywords: needsreview Cc: soldair
Blocked by: Blocking:
Description

in safari (win) and google chrome (only included because the same error occurs and both use webkit)

a call to $("#element").outerWidth({margin:true}) reports the value of parent.innerWidth()

this bug does not happen in any other browser tested

ie6,firefox3,opera9.5,konqueror (tested because khtml is the webkit base)

Attachments (6)
  • jquery_outer_width_chrome.jpg (14.8 KB) - added by soldair September 05, 2008 03:27PM UTC.

    this is s creen shot of the bug in chrome

  • jquery_outer_width_firefox.jpg (21.2 KB) - added by soldair September 05, 2008 03:28PM UTC.

    this is a screenshot of the bug not occuring in firefox

  • jquery_outer_width_ie6.jpg (15.8 KB) - added by soldair September 05, 2008 03:28PM UTC.

    this is a screen shot of the bug not occuring in ie6

  • jquery_outer_width_konqueror.jpg (19.5 KB) - added by soldair September 05, 2008 03:29PM UTC.

    this is a screen shot of the bug not occuring in konqueror

  • jquery_outer_width_opera.jpg (26.4 KB) - added by soldair September 05, 2008 03:31PM UTC.

    this is a screenshot of the bug not occuring in opera

  • jquery_outerwidth_bug.jpg (19.0 KB) - added by soldair September 05, 2008 03:27PM UTC.

    this is a screen shot of the bug in action

Change History (23)

Changed September 05, 2008 03:40PM UTC by flesler comment:1

cc: → soldair
component: coredimensions
owner: → brandon

Changed October 27, 2010 11:06PM UTC by rwaldron comment:2

owner: brandonsoldair
status: newpending

Please provide a distilled and reduced jsFiddle test case, thanks!

Changed November 11, 2010 11:09PM UTC by trac-o-bot comment:3

status: pendingclosed

Automatically closed due to 14 days of inactivity.

Changed December 06, 2010 02:55PM UTC by stenehall@gmail.com comment:4

*bump*

Still broken, (os x 10.6 Safari 5.0.4)

Changed December 06, 2010 03:23PM UTC by jitter comment:5

#5134 is a duplicate of this ticket.

Changed December 06, 2010 03:25PM UTC by jitter comment:6

#3092 is a duplicate of this ticket.

Changed December 06, 2010 03:28PM UTC by jitter comment:7

milestone: 1.31.4.5
priority: majorhigh
status: closedreopened
version: 1.2.61.4.4

test case. It looks like actually the value of margin-right in webkit/chrome is borked.

Changed December 06, 2010 03:28PM UTC by jitter comment:8

status: reopenedopen

Changed January 25, 2011 05:26AM UTC by timmywil comment:9

That's actually the way webkit handles display: block (as in divs). If something needs that property, it means put it on a line by itself. All browsers do this by giving the element (let's call it element A) full width so that it spans the full width of the element it is relative to in order to knock its next sibling down below, which we've all probably noticed when hovering over an H1 or something in web inspector/firebug and saw that it spanned the whole window. However, if you specify a width for element A, browsers need to do something else. The solution webkit chose was give it the necessary margin on the right to accomplish the same thing, regardless of whether the user specifies a margin-right because it ''usually'' won't matter style-wise if it's display block and all proceeding elements go below.

There is an addendum. If the element is display: block; margin-right: 3px; AND float: left; the element MUST keep its margin. You will see that if you add float: left to your #inner in the test case above, you will get the correct outerWidth. This is not a jQuery bug, but a choice on how to implement display: block in webkit.

Regardless, a possible solution would be to float the element in any direction just long enough to get the correct margins, then put it back to what it was before. I went ahead and made a pull request that utilizes swap in getWH in css.js, and added a test in the dimensions component.

Pull request

Changed February 08, 2011 04:09PM UTC by snover comment:10

#8207 is a duplicate of this ticket.

Changed February 08, 2011 04:24PM UTC by jitter comment:11

version: 1.4.41.5

Changed February 22, 2011 02:38PM UTC by jboesch comment:12

_comment0: I think the issue I'm working on relates to this. https://github.com/jboesch/jquery/commit/bc80f2990741891180d64605d750deaf5cdf9b8c \ \ It's not 100% done, tests pass everywhere except 3 in IE7. Still fixing it up.1298385530679355

I think the issue I'm working on relates to this. #4146

https://github.com/jboesch/jquery/commit/bc80f2990741891180d64605d750deaf5cdf9b8c

It's not 100% done, tests pass everywhere except 3 in IE7. Still fixing it up.

Changed February 26, 2011 09:22PM UTC by jboesch comment:13

_comment0: I landed a patch for ticket #4146 which I believe addresses this bug as well: \ http://bugs.jquery.com/ticket/4146 \ \ https://github.com/jquery/jquery/pull/251/files1298836236985583
_comment1: I landed a fix for ticket #4146 which I believe addresses this bug as well: \ http://bugs.jquery.com/ticket/4146 \ \ https://github.com/jquery/jquery/pull/253/files1298836315547006

I landed a fix for ticket #4146 which I believe fixes this bug as well:

http://bugs.jquery.com/ticket/4146

https://github.com/jquery/jquery/pull/253/files

Changed March 24, 2011 03:22PM UTC by rworth comment:14

_comment0: I belive this issue is WebKit only and fixed in nightlies since Feb 2011 \ \ webkit bug: https://bugs.webkit.org/show_bug.cgi?id=13343 \ chromium bug: http://code.google.com/p/chromium/issues/detail?id=23816 \ \ pure JS test case: http://jsfiddle.net/rdworth/XMgur/2/ \ jQuery 1.5.1 test case: http://jsfiddle.net/rdworth/JWqAK/1/1300980515793048

I belive this issue is WebKit only and fixed in nightlies since Feb 2011

Changed March 24, 2011 03:25PM UTC by rworth comment:15

As this issue is WebKit only I think #8443 should be reopened and removed as a duplicate. The test case on #8443 shows an issue in both Safari and IE9. The test cases here (mine and jitter's) show an issue in Safari but not IE9.

Changed March 24, 2011 03:29PM UTC by rworth comment:16

This issue is blocking a regression in jQuery UI 1.8.11 http://bugs.jqueryui.com/ticket/7084

Changed March 24, 2011 03:31PM UTC by rworth comment:17

The best workaround I've found is to set display:inline-block on the element temporarily in order to get the correct computed margin-right value. Though I've only tested so far in Safari 5 on Windows.

Changed March 24, 2011 03:44PM UTC by rwaldron comment:18

cc: soldair
keywords: outerWidthneedsreview
milestone: 1.next1.5.2
priority: highblocker

Changed March 24, 2011 03:46PM UTC by rwaldron comment:19

cc: → soldair

Changed March 24, 2011 06:28PM UTC by john comment:20

owner: soldair
status: openassigned
summary: jquery outerWidth reports incorrect value in saffari (3.1.2 win) and google chrome.css("marginRight") is incorrect in WebKit

Changed March 24, 2011 06:29PM UTC by john comment:21

owner: → rworth

Changed March 24, 2011 10:58PM UTC by Richard Worth comment:22

resolution: → fixed
status: assignedclosed

Added css hook to work around bug in WebKit computed margin-right. Fixes #3333 - .css("marginRight") is incorrect in WebKit

Changeset: c3c507e900fceb419628157504004ab2813b7d01

Changed April 12, 2012 11:28AM UTC by anonymous comment:23