Convert an image to grayscale in HTML/CSS

前端 未结 25 1949
青春惊慌失措
青春惊慌失措 2020-11-22 10:22

Is there a simple way to display a color bitmap in grayscale with just HTML/CSS?

It doesn\'t need to be IE-compatible (and I imagine it won\'t be) -- if

25条回答
  •  青春惊慌失措
    2020-11-22 10:45

    For people who are asking about the ignored IE10+ support in other answers, checkout this piece of CSS:

    img.grayscale:hover {
        filter: url("data:image/svg+xml;utf8,#grayscale");
    }
    
    svg {
        background:url(http://4.bp.blogspot.com/-IzPWLqY4gJ0/T01CPzNb1KI/AAAAAAAACgA/_8uyj68QhFE/s400/a2cf7051-5952-4b39-aca3-4481976cb242.jpg);
    }
    
    svg image:hover {
        opacity: 0;
    }
    

    Applied on this markup:

    
    
    
    
        Grayscaling in Internet Explorer 10+
    
    
    
    
        

    IE10 with inline SVG

    For more demos, checkout IE testdrive's CSS3 Graphics section and this old IE blog http://blogs.msdn.com/b/ie/archive/2011/10/14/svg-filter-effects-in-ie10.aspx

提交回复
热议问题