Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

svg as background image with mask to change the color and with drop-shadow to show the shadow

i am a beginner to code html and css, so a question about svg. when i use the svg as background image and want to change the color also give the shadow, it didn't work with the two properities at the same time. hope someone can help me:

    .image-container {
        width: 100px;
        height: 100px;
        background-size: 100%;
        background-color: #E1A95F;
        -webkit-mask-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/18515/heart.svg");
        -webkit-mask-size: cover;
        filter: drop-shadow(1px 1px 4px rgba(0,0,0,0.75));
    }
   <div class="image-container"></div>
    


 
like image 652
Yichen Dai Avatar asked Oct 14 '25 13:10

Yichen Dai


1 Answers

Apply the mask to a pseudo element because you need an extra element to apply the filter. It should be an element where you don't apply the mask.

.image-container {
  width: 100px;
  height: 100px;
  filter: drop-shadow(1px 1px 4px rgba(0, 0, 0, 0.75));
}
.image-container:before {
  content:"";
  display:block;
  height:100%;
  background-color: #E1A95F;
  -webkit-mask-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/18515/heart.svg");
  -webkit-mask-size: cover;
}
<div class="image-container"></div>
like image 130
Temani Afif Avatar answered Oct 17 '25 01:10

Temani Afif