Skip to content

Instantly share code, notes, and snippets.

@SiGaCode
Created May 23, 2015 10:36
Show Gist options
  • Select an option

  • Save SiGaCode/998ce9781fb5578d8939 to your computer and use it in GitHub Desktop.

Select an option

Save SiGaCode/998ce9781fb5578d8939 to your computer and use it in GitHub Desktop.
Display images in greyscale and fade in color on hover - with SVG and CSS. For portfolios, for example. Credits: http://pandjarov.com/make-your-gallery-fade-to-colour-with-only-svg-and-css/
/*You can modify the “darkness” of the image by playing with the SVG used.*/
/*Hint: Use a specific selector, else it will apply to all pics*/
img {
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");
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
filter: grayscale(100%);
filter: gray; /* IE 6-9 */
}
img:hover {
-webkit-filter: none;
-moz-filter: none;
-ms-filter: none;
filter: none;
-webkit-transition: 1s;
transition: 1s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment