Bug Tracker

Ticket #1599 (closed bug: fixed)

Opened 1 year ago

Last modified 9 months ago

Internet Explorer doesn't like negative values for CSS width

Reported by: kkaefer Assigned to: anonymous
Type: bug Priority: minor
Milestone: 1.2.2 Component: core
Version: 1.2 Keywords:
Cc: Needs: Test Case

Description

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

Change History

Changed 1 year ago by john

  • priority changed from major to minor

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 10 months ago by davidserduke

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

http://www.w3.org/TR/CSS21/visudet.html#propdef-width

I suggest this bug be closed.

Changed 10 months ago by brandon

  • need changed from Patch to Test Case
  • milestone changed from 1.2.1 to 1.2.2

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 10 months ago by brandon

Actually should probably use the test method instead of match.

/^width|height$/.test(name)

Changed 9 months ago by davidserduke

  • status changed from new to closed
  • resolution set to fixed

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

Note: See TracTickets for help on using tickets.