function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computedVal ) {
var i = dimension === "width" ? 1 : 0,
extra = 0,
- delta = 0;
+ delta = 0,
+ marginDelta = 0;
// Adjustment may not be necessary
if ( box === ( isBorderBox ? "border" : "content" ) ) {
for ( ; i < 4; i += 2 ) {
// Both box models exclude margin
+ // Count margin delta separately to only add it after scroll gutter adjustment.
+ // This is needed to make negative margins work with `outerHeight( true )` (gh-3982).
if ( box === "margin" ) {
- delta += jQuery.css( elem, box + cssExpand[ i ], true, styles );
+ marginDelta += jQuery.css( elem, box + cssExpand[ i ], true, styles );
}
// If we get here with a content-box, we're seeking "padding" or "border" or "margin"
) ) || 0;
}
- return delta;
+ return delta + marginDelta;
}
function getWidthOrHeight( elem, dimension, extra ) {
} );
QUnit.test( "outerHeight()", function( assert ) {
- assert.expect( 12 );
+ assert.expect( 14 );
var $div, div,
$win = jQuery( window ),
$div.css( "display", "none" );
assert.equal( $div.outerHeight( true ), 94, "Test hidden div with padding, border and margin with margin option" );
+ $div.css( "display", "" );
+ $div.css( "margin", "-10px" );
+ assert.equal( $div.outerHeight(), 74, "Test with padding, border and negative margin without margin option" );
+ assert.equal( $div.outerHeight( true ), 54, "Test with padding, border and negative margin with margin option" );
+
// reset styles
$div.css( { "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" } );