Bug Tracker

Modify

Ticket #1599 (closed bug: fixed)

Opened 6 years ago

Last modified 14 months ago

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

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.

Change History

comment:1 Changed 6 years 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.

comment:2 Changed 6 years 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.

comment:3 Changed 6 years 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 ];

comment:4 Changed 6 years ago by brandon

Actually should probably use the test method instead of match.

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

comment:5 Changed 5 years 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.

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.