Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firefox svg grayscale issue - image gets blurred and shifts

Tags:

html

css

I am using the following CSS to get a grayscale effect on hover. The issue in Firefox is that it blurs the image slightly and also shifts it to the right by 1–2 pixels. I am not sure why this is happening.

Is this an inherent issue? How can I solve it?

.zd-stack img:hover {
    filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale");
                                         /* Firefox 10+ */
    filter: gray;                        /* IE6-9 */
    -webkit-filter: grayscale(100%);     /* Chrome 19+ & Safari 6+ */
    -webkit-transition: all .6s ease;    /* Fade to color for Chrome and Safari */
    -webkit-backface-visibility: hidden; /* Fix for transition flickering */;
}

I want to use CSS, but don't know how to correct this minor issue!

like image 294
Devender Bhandari Avatar asked May 07 '13 05:05

Devender Bhandari


1 Answers

The issue between Firefox and SVG grayscale seems to be fixed now.

See the fiddle with your code sample: https://jsfiddle.net/tzi/rjotsz0p/


Firefox supports grayscale() filter from version 35 (January 2015), so you can now have a much better version of this code:

.zd-stack img {
    transition: filter .6s ease;         /* Standard (all but IE10+) */
}

.zd-stack img:hover {
    filter: gray;                        /* For IE6-12 */
    filter: grayscale(100%);             /* Standard (only FF35+ & IE13+) */
    -webkit-filter: grayscale(100%);     /* For Chrome, Safari & Opera */
}

See the fiddle with this new code: https://jsfiddle.net/tzi/x6xcx68g/

like image 200
tzi Avatar answered Oct 01 '22 17:10

tzi