9

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!

gfullam
  • 11,531
  • 5
  • 50
  • 64
  • if really you feel this is problem please raise bug http://bugzilla.mozilla.org – Ankur Loriya May 07 '13 at 06:00
  • it seems like a bug only on firefox, when I remove that particular line of css meant for ff and add some other hover style it seems fine. Something to do with cross domain css svg?...but anyway for now I have removed it. – Devender Bhandari May 08 '13 at 10:40
  • Is this your answer? http://stackoverflow.com/a/32391958/241291 – cobaltduck Dec 16 '15 at 16:03

1 Answers1

1

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/

tzi
  • 8,719
  • 2
  • 25
  • 45