How to dim an image keeping transparency untouched with CSS or JS?

前端 未结 4 875
隐瞒了意图╮
隐瞒了意图╮ 2021-02-13 18:14

Normal approach to dimming an image suggested everywhere is to change it\'s opacity attribute and display something dark under it. However, my image has transparency and is on w

4条回答
  •  半阙折子戏
    2021-02-13 18:33

    Another way to do this would be by using new CSS mask property (currently fully supported only by webkit) on the div with the darkening.

    .dim {
      display: none;
      /*Also position it above the image*/
     }
    
    .dim:hover {
     background-color: black;
     opacity: 0.5;
     -webkit-mask: url(image.png) top left / cover;
    }
    

提交回复
热议问题