Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix blurry Image on transform scale

When i put transform: scale(1.1); on hover on some element the image became blurry. How to fix this bug?

Example

enter image description here

like image 457
Viktor Zahov Avatar asked Apr 22 '16 07:04

Viktor Zahov


People also ask

Why are my images blurry in HTML?

You are setting the size of the image 150x150, which may be different from the original ratio. Since the image must be resize to that ratio it could lead to this behavior. You may either try to use only width or height and let the other property auto calculated, or you can try using max-height or max-width instead.

How do you keep resolution when resizing CSS?

Use object fit property in your css, and give a fixed width and height to your image tag or respective class so that every image will have same width and height, Now Your Image won't be distorted.


2 Answers

Try this, it's work fine for me!

img {
    -webkit-backface-visibility: hidden; 
    -ms-transform: translateZ(0); /* IE 9 */
    -webkit-transform: translateZ(0); /* Chrome, Safari, Opera */
    transform: translateZ(0);
}
like image 158
dimitar Avatar answered Oct 25 '22 09:10

dimitar


TL;DR transform: scale is actually scaling the original image, and because you are leaving it to the browser's render engine to figure out what should go there you got a blurry image. try

img {
transform: scale(.9)    
}

img:hover {
transform: scale(1)
}

Aaron Sibler answered the question for me.

I just experienced this riddle. In your example, you’ll need to transform img DOWN something like “transform: scale(0.7)” and then scale UP to the images native dimensions on hover like “transform: scale(1.0)”

The scale value is relative to the original image’s dimensions – not their current dimensions on screen so a scale of 1 always equals the original image’s dimensions.

I’ve used this here;

http://meetaaronsilber.com/experiments/css3imgpop/index.html

like image 40
axecopfire Avatar answered Oct 25 '22 09:10

axecopfire