Change color of PNG image via CSS?

后端 未结 16 1389
自闭症患者
自闭症患者 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:52

    body{
      background: #333 url(/images/classy_fabric.png);
      width: 430px;
      margin: 0 auto;
      padding: 30px;
    }
    .preview{
      background: #ccc;
      width: 415px;
      height: 430px;
      border: solid 10px #fff;
    }
    
    input[type='radio'] {
      -webkit-appearance: none;
      -moz-appearance: none;
      width: 25px;
      height: 25px;
      margin: 5px 0 5px 5px;
      background-size: 225px 70px;
      position: relative;
      float: left;
      display: inline;
      top: 0;
      border-radius: 3px;
      z-index: 99999;
      cursor: pointer;
      box-shadow: 1px 1px 1px #000;
    }
    
    input[type='radio']:hover{
      -webkit-filter: opacity(.4);
      filter: opacity(.4);    
    }
    
    .red{
      background: red;
    }
    
    .red:checked{
      background: linear-gradient(brown, red)
    }
    
    .green{
      background: green;
    }
    
    .green:checked{
      background: linear-gradient(green, lime);
    }
    
    .yellow{
      background: yellow;
    }
    
    .yellow:checked{
      background: linear-gradient(orange, yellow);
    }
    
    .purple{
      background: purple;
    }
    
    .pink{
      background: pink;
    }
    
    .purple:checked{
      background: linear-gradient(purple, violet);
    }
    
    .red:checked ~ img{
      -webkit-filter: opacity(.5) drop-shadow(0 0 0 red);
      filter: opacity(.5) drop-shadow(0 0 0 red);
    }
    
    .green:checked ~ img{
      -webkit-filter: opacity(.5) drop-shadow(0 0 0 green);
      filter: opacity(.5) drop-shadow(0 0 0 green);
    }
    
    .yellow:checked ~ img{
      -webkit-filter: opacity(.5) drop-shadow(0 0 0 yellow);
      filter: opacity(.5) drop-shadow(0 0 0 yellow);
    }
    
    .purple:checked ~ img{
      -webkit-filter: opacity(.5) drop-shadow(0 0 0 purple);
      filter: opacity(.5) drop-shadow(0 0 0 purple);
    }
    
    .pink:checked ~ img{
      -webkit-filter: opacity(.5) drop-shadow(0 0 0 pink);
      filter: opacity(.5) drop-shadow(0 0 0 pink);
    }
    
    
    img{
      width: 394px;
      height: 375px;
      position: relative;
    }
    
    .label{
      width: 150px;
      height: 75px;
      position: absolute;
      top: 170px;
      margin-left: 130px;
    }
    
    ::selection{
      background: #000;
    }

    Source: https://codepen.io/taryaoui/pen/EKkcu

提交回复
热议问题