将混合模式仅应用于阴影 [英] Apply blend mode to drop-shadow only

查看:115
本文介绍了将混合模式仅应用于阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以仅将元素的阴影与重叠元素的颜色融合在一起?

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.

如果我想将效果应用于包括阴影的整个元素,则可以使用mix-blend-mode:乘法来实现.我实际上只想在阴影上使用mix-blend-mode-可以做到吗?

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?

推荐答案

您不能执行此操作,但是您可以执行的操作是将阴影应用到大小相同并使用乘法混合的伪元素上模式.

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.

这篇关于将混合模式仅应用于阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆