Zoom Vs. Scale in CSS3
Solution 1:
Transform is more predictable than zoom across browsers.
Zoom affects positioning differently in different browsers.
example:
position:absolute; left:50px; zoom: 50%;
- IE will not change the
left
value at all. - Chrome will change the left value to
25px
. Effectively it does doleft = left * zoom
. But DevTools Computed Values in DevTools will still displayleft: 50px
, even though that is effectively not true due to the zoom.
Transform is handled the same way in all browsers (as far as I can tell).
example:
position:absolute; left:50px; transform: scale(0.5)
-
left
would effectively be set to25px
in both Chrome and IE. (again, computed values will still not reflect this, it will displayleft:50px
) - To avoid changing the
left
value, simply usetransform-origin: 0 0
. That will ensure left is still 50px.
Demo: http://jsfiddle.net/4z728fmk/ shows 2 boxes where the small one is zoomed or scaled to 50%. Looks like this:
edit: img updated 2016-06-16 with Firefox (nothing had change in Chrome or IE since last time)
Solution 2:
Complementary to Drkawashima's answer:
-
zoom
doesn't work in Firefox at all. See caniuse -
Once upon a time (fairy tale ends here sorry),
zoom: 1;
was the mighty declaration that helped to debug IE6. It conferred the element it was applied an internal "switch" to this browser named hasLayout (not a CSS property, just a concept like "clearfix" is). You'll findposition: relative; zoom: 1;
quite a lot in old projects