Image Greyscale with CSS & re-color on mouse-over?

前端 未结 5 1330
别那么骄傲
别那么骄傲 2020-11-27 09:47

I am looking to take an icon that is colored (and will be a link) and turn it greyscale until the user places their mouse over the icon (where it would then color the image)

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 10:11

    Answered here: Convert an image to grayscale in HTML/CSS

    You don't even need to use two images which sounds like a pain or an image manipulation library, you can do it with cross browser support (current versions) and just use CSS. This is a progressive enhancement approach which just falls back to color versions on older browsers:

    img {
      filter: url(filters.svg#grayscale);
      /* Firefox 3.5+ */
      filter: gray;
      /* IE6-9 */
      -webkit-filter: grayscale(1);
      /* Google Chrome & Safari 6+ */
    }
    img:hover {
      filter: none;
      -webkit-filter: none;
    }
    

    and filters.svg file like this:

    
      
        
      
    
    

提交回复
热议问题