Skip to content

Commit 7e02cee

Browse files
committed
Make sure that the correct height/width of the elements is retreived. Fixes #7225.
1 parent d9a3e00 commit 7e02cee

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/css.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,23 @@ jQuery.each(["height", "width"], function( i, name ) {
169169
});
170170
}
171171

172-
if ( val < 0 || val === 0 && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
172+
if ( val < 0 ) {
173173
return elem.style[ name ] || "0px";
174174
}
175175

176-
return val + "px";
176+
if ( val === 0 ) {
177+
val = curCSS( elem, name, name );
178+
179+
if ( val != null ) {
180+
return val;
181+
}
182+
}
183+
184+
if ( val < 0 || val == null ) {
185+
return elem.style[ name ];
186+
}
187+
188+
return typeof val === "string" ? val : val + "px";
177189
}
178190
},
179191

test/unit/css.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module("css");
22

33
test("css(String|Hash)", function() {
4-
expect(42);
4+
expect(41);
55

66
equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"');
77

@@ -13,21 +13,19 @@ test("css(String|Hash)", function() {
1313

1414
var div = jQuery( "<div>" );
1515

16-
equals( div.css("width"), "0px", "Width on disconnected node." );
17-
equals( div.css("height"), "0px", "Height on disconnected node." );
16+
equals( div.css("width") || "auto", "auto", "Width on disconnected node." );
17+
equals( div.css("height") || "auto", "auto", "Height on disconnected node." );
1818

1919
div.css({ width: 4, height: 4 });
2020

2121
equals( div.css("width"), "4px", "Width on disconnected node." );
2222
equals( div.css("height"), "4px", "Height on disconnected node." );
2323

24-
var div2 = jQuery( "<div style='display:none;'><input type='text'/><textarea/></div>").appendTo("body");
24+
var div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body");
2525

26-
equals( div2.find("input").css("width"), "0px", "Width on hidden input." );
27-
equals( div2.find("input").css("height"), "0px", "Height on hidden input." );
28-
29-
equals( div2.find("textarea").css("width"), "0px", "Width on hidden textarea." );
30-
equals( div2.find("textarea").css("height"), "0px", "Height on hidden textarea." );
26+
equals( div2.find("input").css("height"), "20px", "Height on hidden input." );
27+
equals( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
28+
equals( div2.find("div").css("height"), "20px", "Height on hidden textarea." );
3129

3230
div2.remove();
3331

0 commit comments

Comments
 (0)