Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply blend mode to drop-shadow only

Is it possible to blend only the drop-shadow of an element with the color of the element it is overlapping?

For example: I have one element overlapping the other. The element on top has a light-grey drop shadow. The element below is black. I don't want any blend applied to either of the elements themselves but want the drop-shadow of the overlapping element to blend with color of the element below, creating a darker grey where the shadow falls on the overlapped element.

If I wanted to apply the effect to the entire element including the drop-shadow then this can be achieved using mix-blend-mode: multiply. I effectively want to use mix-blend-mode on the drop-shadow only - can this be done?

like image 943
mannystar Avatar asked Oct 16 '18 14:10

mannystar


People also ask

What does exclusion blending mode do?

Exclusion. Exclusion is very similar to Difference. Blending with white inverts the base color values, while blending with black produces no change. However, Blending with 50% gray produces 50% gray.

How to change blending mode of a layer in After Effects?

To cycle through blending modes for selected layers, hold down the Shift key and press - (hyphen) or = (equal sign) on your main keyboard.

What is filter drop shadow?

filter: drop-shadow(0 0 0.75rem crimson); A drop shadow is effectively a blurred, offset version of the input image's alpha mask, drawn in a specific color and composited below the image. Note: This function is somewhat similar to the box-shadow property.

How does box shadow work?

The box-shadow CSS property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.


1 Answers

You can't do this, but what you can do is apply the drop-shadow to a pseudo-element that is the same size and uses a multiply blend mode.

.above {
    position: absolute;
    background: green;
    width: 100px;
    height: 100px;
}

.above::before {
    box-shadow: 3pt 3pt 0 0 dodgerblue;
    mix-blend-mode: multiply;
    content: "";

    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
}

.below {
    position: absolute;
    top: 50px;
    left: 50px;

    width: 100px;
    height: 100px;

    background: red;
}
<div class="below">
</div>
<div class="above">
</div>

I used these colours for illustrative purposes, but you can replace them with your own.

like image 54
laptou Avatar answered Oct 15 '22 04:10

laptou