Skip to main content

Bug Tracker

Side navigation

#1599 closed bug (fixed)

Opened September 12, 2007 11:42AM UTC

Closed November 28, 2007 04:56AM UTC

Last modified March 15, 2012 01:32AM UTC

Internet Explorer doesn't like negative values for CSS width

Reported by: kkaefer Owned by:
Priority: minor Milestone: 1.2.2
Component: core Version: 1.2
Keywords: Cc:
Blocked by: Blocking:

The follwoing code causes IE (at least IE 7) to throw a script error:

$(function() { $('div').width(-1); });

(if .size() is > 0).

Obviously, it doesn't like negative values for width.

Attachments (0)
Change History (5)

Changed September 15, 2007 03:34AM UTC by john comment:1

priority: majorminor

This is a really minor issue - you shouldn't be setting negative widths to begin with - but I'm not a fan of throwing errors, so I'll look into it at some point.

Changed November 06, 2007 07:37PM UTC by davidserduke comment:2

The CSS2.1 spec states "Negative values for 'width' are illegal."

I suggest this bug be closed.

Changed November 15, 2007 02:22PM UTC by brandon comment:3

need: PatchTest Case

What is the expected behavior? Should the width then be set to 0 instead of -1 or just ignored?

I would expect the result to be 0 but a quick run in firebug shows that firefox just ignores negative numbers for width and height.

I'm leaning towards fixing this so that the results while using jQuery are consistent cross-browser.

Index: jquery/src/core.js
--- jquery/src/core.js	(revision 3826)
+++ jquery/src/core.js	(working copy)
@@ -1058,7 +1058,8 @@
 				return letter.toUpperCase();
-			if ( value != undefined )
+			// ignore negative numbers for width and height
+			if ( value != undefined && (name.match(/^width|height$/) && parseFloat(value) > 0) )
 				elem[ name ] = value;
 			return elem[ name ];

Changed November 16, 2007 12:45AM UTC by brandon comment:4

Actually should probably use the test method instead of match.


Changed November 28, 2007 04:56AM UTC by davidserduke comment:5

resolution: → fixed
status: newclosed

Fixed in [3959] as Brandon suggested to ignore negative numbers for width and height css values.