-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Description
jQuery 3.2.1 reports wrong sizes for elements with box-sizing: border-box in Chrome (v61) on certain browser zoom levels. It seems to add the element's insets (padding + border) to its width and height, although the CSS width already includes the insets.
Demonstration
http://output.jsbin.com/yipudeloya/
In the provided test case, we have two <div>s with 10px padding on all sides, 1px border on all sides and a CSS width/height set to 32px. Because box-sizing is set to border-box, the visual size of the elements is 32x32px with a remaining "inner" space of 10px. At 100% browser zoom level, this is correctly reported both by css('width') and .outerWidth().
If we now zoom to 110%, the numbers get slightly changed, probably due to some rounding errors (31.9886px instead of 32px). Because we should always get "CSS pixels" that are not affected by browser zoom, I would have expected those numbers to stay the same - but I can live with that. The real problem occurs when you reload the page while having the browser zoom at 110%! Now the width is completely incorrect (53.977236000000005px instead of 32px).
If the page uses those values for programmatic layout, the results will be wrong. You can see the effect in the demo. The CSS width and height of the first <div> are copied to the second, so they should always be the same size. However, if you start at 100%, the second <div> is much larger.
Analysis
Analysis has shown that this seems to be caused by the internal function computeStyleTests() in css/support.js that wrongly sets the internal property boxSizingReliableVal to false. Apparently, this happens because of a rounding error. In my case, the test div's measured width is 3.997px, which is not equal to the expected value of 4px. What's worse, this internal property is only calculated once! So when you start at 110% zoom, and then reset it to 100%, the problem still persists until you completely reload the page.
I could observe the problem at the following zoom levels: 110%, 90%, 80%, 67% and 33%.
Firefox (v56) and IE (v11) don't seem to be affected by this problem. Also, with jQuery 2.1.4, everything works fine on all browsers. All tests were performed on Windows 7 with default DPI and font size settings.