🌐 AI搜索 & 代理 主页
Skip to content

Commit 5fc77d1

Browse files
committed
CSS: Don't auto-append "px" to CSS variables
Fixes gh-4063
1 parent f8c1e90 commit 5fc77d1

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/css.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ jQuery.extend( {
246246
}
247247

248248
// If a number was passed in, add the unit (except for certain CSS properties)
249-
if ( type === "number" ) {
249+
// The isCustomProp check can be removed in jQuery 4.0 when we only auto-append
250+
// "px" to a few hardcoded values.
251+
if ( type === "number" && !isCustomProp ) {
250252
value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
251253
}
252254

test/unit/css.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,21 @@ QUnit.test( "Do not throw on frame elements from css method (#15098)", function(
16581658
assert.equal( $elem.css( "--prop5" ), "'val5'", "Works with single quotes" );
16591659
}
16601660
} );
1661+
1662+
QUnit[ supportsCssVars ? "test" : "skip" ]( "Don't append px to CSS vars", function( assert ) {
1663+
assert.expect( 3 );
1664+
1665+
var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
1666+
1667+
$div
1668+
.css( "--a", 3 )
1669+
.css( "--line-height", 4 )
1670+
.css( "--lineHeight", 5 );
1671+
1672+
assert.equal( $div.css( "--a" ), "3", "--a: 3" );
1673+
assert.equal( $div.css( "--line-height" ), "4", "--line-height: 4" );
1674+
assert.equal( $div.css( "--lineHeight" ), "5", "--lineHeight: 5" );
1675+
} );
16611676
} )();
16621677

16631678
}

0 commit comments

Comments
 (0)