Silhouette a PNG image using CSS

前端 未结 4 1478
北恋
北恋 2020-12-06 19:46

Anyone know of a way that I can get CSS to make a PNG image with transparency look completely blacked out like a silhouette?

In other words- Going from something li

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 20:39

    Nowdays, filter combined to mix-blend-mode could do too :

    span {/* to be used to lay the 'blender mask' over img */
      position: relative;
      display: inline-block;
      overflow:hidden;
    }
    
    span img {
      display: block;/* erase gap */
      max-width:45vw;
      filter: contrast(150%);
    }
    span + span img {
      filter: contrast(120%) saturate(0%);/* saturate(0%) is  similar to grayscale(100%) */
    }
    
    span:before {
      content: '';
      z-index: 1;
      height: 100%;
      background: white;
      position: absolute;
      top: 0;
      width: 100%;
      display: block;
      filter: contrast(10000%) brightness(0) saturate(100%) grayscale(100%);
      mix-blend-mode: color-burn;/* bake it to black */
      animation : span 2s infinite alternate;
    }
    @keyframes span {
      from{
        transform:translate(-100%,0)
      }
      25%,50% {
        transform:translate(0,0);
      }
      to{
        transform:translate(100%,0)
      }
    }
    
    

提交回复
热议问题