简体   繁体   English

将蒙版应用到 box-shadow

[英]Applying mask to box-shadow

I have a div with a mask applied to it.我有一个应用了mask的 div。 I noticed that I can't apply a box-shadow on that same div, so I must move the shadow to a "wrapper" div.我注意到我不能在同一个 div 上应用box-shadow ,所以我必须将阴影移动到“包装器”div。

The problem is that if the shadow is placed on the shadow div, the mask is not applied to the shadow.问题是,如果将阴影放在阴影 div 上,则mask不会应用于阴影。

How can I apply a mask to a div and to it's shadow?如何将mask应用于 div 及其阴影?

 .wrapper { width: 200px; height: 200px; box-shadow: 17px 13px 7px 3px rgba(0,0,0,0.75); } .b { width: 200px; height: 200px; background-color: yellow; border: 2px solid black; -webkit-mask: radial-gradient( circle at center top, transparent 30px, black 31px ) top / 100% 51%, radial-gradient( circle at right bottom, transparent 30px, black 31px ) right bottom / 51% 51%, radial-gradient( circle at left bottom, transparent 30px, black 31px ) left bottom / 51% 51%; -webkit-mask-repeat: no-repeat; }
 <div class="wrapper"> <div class="b"></div> </div>

You need a drop-shadow, not a box-shadow:你需要一个阴影,而不是一个盒子阴影:

 .wrapper { width: 200px; height: 200px; filter:drop-shadow(17px 13px 7px rgba(0,0,0,0.75)); } .b { width: 200px; height: 200px; background-color: yellow; border: 2px solid black; -webkit-mask: radial-gradient( circle at center top, transparent 30px, black 31px ) top / 100% 51%, radial-gradient( circle at right bottom, transparent 30px, black 31px ) right bottom / 51% 51%, radial-gradient( circle at left bottom, transparent 30px, black 31px ) left bottom / 51% 51%; -webkit-mask-repeat: no-repeat; }
 <div class="wrapper"> <div class="b"></div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM