@@ -148,10 +148,10 @@ function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computed
148148function getWidthOrHeight ( elem , dimension , extra ) {
149149
150150 // Start with computed style
151- var valueIsBorderBox ,
152- styles = getStyles ( elem ) ,
151+ var styles = getStyles ( elem ) ,
153152 val = curCSS ( elem , dimension , styles ) ,
154- isBorderBox = jQuery . css ( elem , "boxSizing" , false , styles ) === "border-box" ;
153+ isBorderBox = jQuery . css ( elem , "boxSizing" , false , styles ) === "border-box" ,
154+ valueIsBorderBox = isBorderBox ;
155155
156156 // Computed unit is not pixels. Stop here and return.
157157 if ( rnumnonpx . test ( val ) ) {
@@ -160,7 +160,7 @@ function getWidthOrHeight( elem, dimension, extra ) {
160160
161161 // Check for style in case a browser which returns unreliable values
162162 // for getComputedStyle silently falls back to the reliable elem.style
163- valueIsBorderBox = isBorderBox &&
163+ valueIsBorderBox = valueIsBorderBox &&
164164 ( support . boxSizingReliable ( ) || val === elem . style [ dimension ] ) ;
165165
166166 // Fall back to offsetWidth/Height when value is "auto"
@@ -367,14 +367,26 @@ jQuery.each( [ "height", "width" ], function( i, dimension ) {
367367 set : function ( elem , value , extra ) {
368368 var matches ,
369369 styles = getStyles ( elem ) ,
370+ isBorderBox = jQuery . css ( elem , "boxSizing" , false , styles ) === "border-box" ,
370371 subtract = extra && boxModelAdjustment (
371372 elem ,
372373 dimension ,
373374 extra ,
374- jQuery . css ( elem , "boxSizing" , false , styles ) === "border-box" ,
375+ isBorderBox ,
375376 styles
376377 ) ;
377378
379+ // Account for unreliable border-box dimensions by comparing offset* to computed and
380+ // faking a content-box to get border and padding (gh-3699)
381+ if ( isBorderBox && ! support . borderBoxReliable ( ) ) {
382+ subtract -= Math . ceil (
383+ elem [ "offset" + dimension [ 0 ] . toUpperCase ( ) + dimension . slice ( 1 ) ] -
384+ parseFloat ( styles [ dimension ] ) -
385+ boxModelAdjustment ( elem , dimension , "border" , false , styles ) -
386+ 0.5
387+ ) ;
388+ }
389+
378390 // Convert to pixels if value adjustment is needed
379391 if ( subtract && ( matches = rcssNum . exec ( value ) ) &&
380392 ( matches [ 3 ] || "px" ) !== "px" ) {
0 commit comments