Convert an image to grayscale in HTML/CSS

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

    As a complement to other's answers, it's possible to desaturate an image half the way on FF without SVG's matrix's headaches:

    
    

    Where $v is between 0 and 1. It's equivalent to filter:grayscale(50%);.

    Live example:

    .desaturate {
        filter: url("#desaturate");
        -webkit-filter: grayscale(50%);
    }
    figcaption{
        background: rgba(55, 55, 136, 1);
        padding: 4px 98px 0 18px;
        color: white;
        display: inline-block;
        border-top-left-radius: 8px;
        border-top-right-radius: 100%;
        font-family: "Helvetica";
    }
    
      
      	
      
    
    
    
    Original
    Half grayed

    Reference on MDN

提交回复
热议问题