How to “tint” image with css

前端 未结 6 1821
你的背包
你的背包 2020-12-15 04:05

I try to tint an image with the background attribute like this:

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 05:06

    Changing the opacity of the parent container changes all children. make a separate div to control your tint. I hammered something together, but the essentials are there.

    .image-holder {
      position: relative;
      max-height: 250px;
      max-width: 200px;
    }
    
    .image-holder img {
      display: block;
      opacity: 0.5;
      max-width: 100%;
      max-height: inherit;
    }
    
    .tint {
      position: absolute;
      max-height: 250px;
      max-width: 200px;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      margin: 0;
      opacity: 0;
      background: #00f;
      transition: opacity 1s;
    }
    
    .image-holder:hover .tint {
      opacity: 1;
    }

提交回复
热议问题