Change color of PNG image via CSS?

后端 未结 16 1706
自闭症患者
自闭症患者 2020-11-22 07:33

Given a transparent PNG displaying a simple shape in white, is it possible to somehow change the color of this through CSS? Some kind of overlay or what not?

16条回答
  •  星月不相逢
    2020-11-22 07:47

    You can use filters with -webkit-filter and filter: Filters are relatively new to browsers but supported in over 90% of browsers according to the following CanIUse table: https://caniuse.com/#feat=css-filters

    You can change an image to grayscale, sepia and lot more (look at the example).

    So you can now change the color of a PNG file with filters.

    body {
        background-color:#03030a;
        min-width: 800px;
        min-height: 400px
    }
    img {
        width:20%;
        float:left; 
         margin:0;
    }
    /*Filter styles*/
    .saturate { filter: saturate(3); }
    .grayscale { filter: grayscale(100%); }
    .contrast { filter: contrast(160%); }
    .brightness { filter: brightness(0.25); }
    .blur { filter: blur(3px); }
    .invert { filter: invert(100%); }
    .sepia { filter: sepia(100%); }
    .huerotate { filter: hue-rotate(180deg); }
    .rss.opacity { filter: opacity(50%); }
    
    Mona Lisa
    Mona Lisa
    Mona Lisa
    Mona Lisa
    Mona Lisa
    Mona Lisa
    Mona Lisa
    Mona Lisa
    Mona Lisa
    Mona Lisa

    Source

提交回复
热议问题