简体   繁体   English

为梯形添加阴影

[英]Adding shadow to trapezoid

First of all, this question might be similar to this , but the shape in my case is different, so it couldn't really help me out. 首先,这个问题可能与类似,但是在我的情况下,形状是不同的,因此它并不能真正帮助我。

The trapezoid code is the following: 梯形代码如下:

 #light { /*setting the element*/ border-bottom: 164px solid grey; border-left: 148px solid transparent; border-right: 165px solid transparent; height: 0; width: 80px; } 
 <div id="light"></div> 

Just to clarify, I am trying to add the shadow effect, similar to the following example: 为了澄清起见,我试图添加阴影效果,类似于以下示例:

 #bulb { /*setting the element*/ background: grey; width: 200px; height: 200px; border-radius: 50%; /*adding "light" (shadow)*/ box-shadow: 0 0 100px 10px rgba(128, 128, 128, 0.5); } 
 <div id="bulb"></div> 

When I try to add the regular box-shadow: , my trapezoid becomes a regular rectangle with white parts. 当我尝试添加常规的box-shadow: ,梯形变为带有白色部分的常规矩形。

Instead of a box-shadow you could use a drop-shadow filter, eg 除了使用box-shadow还可以使用drop-shadow滤镜,例如

filter: drop-shadow(0 0 40px #222);

 #light { /*setting the element*/ border-bottom: 164px solid grey; border-left: 148px solid transparent; border-right: 165px solid transparent; height: 0; width: 80px; filter: drop-shadow(0 0 40px #222); } 
 <div id="light"></div> 

More info on MDN 有关MDN的更多信息

I would create the shape differently using pseudo element with a blur effect: 我会使用带有模糊效果的伪元素以其他方式创建形状:

 #light { width:400px; height:160px; position:relative; } #light:before, #light:after{ content:""; position:absolute; top:0; left:0; right:0; bottom:0; background: /*triangle on the right*/ linear-gradient(to top right,grey 49.5%,transparent 50%) right/150px 100%, /*triangle on the left*/ linear-gradient(to top left, grey 49.5%,transparent 50%) left /150px 100%, /*rectangle at the center*/ linear-gradient(grey,grey) center/100px 100%; background-repeat:no-repeat; } #light:before { filter:blur(20px); } 
 <div id="light"> </div> 

based on css-tricks Double-Box Method you can "have a container box with hidden overflow and another box inside it which is rotate and hangs out of it" 基于css-tricks Double-Box方法,您可以"have a container box with hidden overflow and another box inside it which is rotate and hangs out of it"

 .light { width: 350px; height: 135px; position: relative; overflow: hidden; box-shadow: 0 16px 10px -17px rgba(0, 0, 0, 0.5); } .light:after { content: ""; position: absolute; width: 300px; height: 300px; background: #999; transform: rotate(45deg); top: 25px; left: 25px; box-shadow: -1px -1px 10px -2px rgba(0, 0, 0, 0.5); } 
 <div class="light"></div> 

In your example, you can't add a proper box-shadow without having these white parts on each side. 在您的示例中,如果没有每个侧面的白色部分, 则无法添加适当的阴影。 That is because the CSS border colouring the grey shaped trapeziod DIV. 那是因为CSS边框为灰色的梯形DIV着色。

In the example above, they are using an .SVG file (image), since it is an image, the original shape of it is a trapezoid, not a rectangle with white side like yours. 在上面的示例中,他们使用的是.SVG文件 (图像),因为它是图像,所以它的原始形状是梯形,而不是像您一样带有白色边的矩形。

You will need to draw an .svg in the shape and color you want, and then add a shadow to the element itself. 您将需要以所需的形状和颜色绘制.svg,然后向元素本身添加阴影。

Here are more informations about SVG . 这是有关SVG的更多信息

I hope it helps. 希望对您有所帮助。

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

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