Convert an image to grayscale in HTML/CSS

前端 未结 25 1918
青春惊慌失措
青春惊慌失措 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:59

    For Firefox you don't need to create a filter.svg file, you can use data URI scheme.

    Taking up the css code of the first answer gives:

    filter: url("data:image/svg+xml;utf8,#grayscale"); /* Firefox 3.5+ */
    filter: grayscale(100%); /* Current draft standard */
    -webkit-filter: grayscale(100%); /* New WebKit */
    -moz-filter: grayscale(100%);
    -ms-filter: grayscale(100%); 
    -o-filter: grayscale(100%);
    filter: gray; /* IE6+ */
    

    Take care to replace "utf-8" string by your file encoding.

    This method should be faster than the other because the browser will not need to do a second HTTP request.

提交回复
热议问题