Gray out image with CSS?

后端 未结 9 2177
轮回少年
轮回少年 2020-12-02 03:55

What\'s the best way (if any) to make an image appear \"grayed out\" with CSS (i.e., without loading a separate, grayed out version of the image)?

My context is that

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 04:29

    Your here:

    
    

    Css Gray:

    img{
        filter: url("data:image/svg+xml;utf8,#grayscale"); /* Firefox 10+, Firefox on Android */
        filter: grayscale(100%);
        -moz-filter: grayscale(100%);
        -ms-filter: grayscale(100%);
        -o-filter: grayscale(100%);
        filter: gray; /* IE6-9 */
        -webkit-filter: grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */}
    

    Ungray:

    a:hover img{
        filter: url("data:image/svg+xml;utf8,#grayscale");
        filter: grayscale(0%);
        -moz-filter: grayscale(0%);
        -ms-filter: grayscale(0%);
        -o-filter: grayscale(0%);
        filter: none ; /* IE6-9 */
        zoom:1; /* needed to trigger "hasLayout" in IE if no width or height is set */
        -webkit-filter: grayscale(0%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */
        }
    

    I found it at: http://zkiwi.com/topic/chuyen-hinh-mau-thanh-trang-den-bang-css-nhu-the-nao

    Edit: IE10+ does not support DX filters as IE9 and earlier have done, nor does it support a prefixed version of the greyscale filter. You can fix it, use one in two solutions below:

    1. Set IE10+ to render using IE9 standards mode using the following meta element in the head:
    2. Use an SVG overlay in IE10 to accomplish the greyscaling internet explorer 10 - howto apply grayscale filter?

提交回复
热议问题