CSS filter: make color image with transparency white

前端 未结 2 1995
花落未央
花落未央 2021-01-29 19:41

I have a colored png image with transparency. I would like to use css filter to make the whole image white but leave the transparency as it is. Is that possible in CSS?

2条回答
  •  日久生厌
    2021-01-29 20:20

    You can use

    filter: brightness(0) invert(1);
    

    html {
      background: red;
    }
    p {
      float: left;
      max-width: 50%;
      text-align: center;
    }
    img {
      display: block;
      max-width: 100%;
    }
    .filter {
      -webkit-filter: brightness(0) invert(1);
      filter: brightness(0) invert(1);
    }

    Original:

    Filter:

    First, brightness(0) makes all image black, except transparent parts, which remain transparent.

    Then, invert(1) makes the black parts white.

提交回复
热议问题