Let's say I have this clip path (a triangle generated here)
-webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%); clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
Is it possible to create a box-shadow from this clip path? Something like this:
box-shadow: 20px 25px 50px -25px #000;
clipped Object using Clip-Path() function of CSS. Approach: We are going to create two divs, one for the main and the other for our clipped shape. Then we are going to use the drop-shadow() function to apply shadow effects.
Using transforms on the box-shadow (& transform ) property, we can create the illusion of an element moving closer or further away from the user.
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.
You can use a filter on the containing div, try:
.container { filter: drop-shadow(0px 10px 5px rgba(0,0,0,0.1)) }
eg: https://plnkr.co/edit/kePuv7OLQwawPjiBLg3J?p=preview
I'm assuming you mean, is it possible to create the shadow along the polygon. If so, then no. box-shadow
is unfortunately only a "box", so it can't follow the clip path. It'd still apply to the rectangle of the element itself.
You could however pair it with another element that has the same clipping, but is set below it and offset and create a pseudo-shadow:
#box { position: relative; width: 200px; height: 200px; } #content { width: 100%; height: 100%; background: #3CF; -webkit-clip-path: polygon(0 100%, 0 0, 100% 0, 80% 100%); } #shadow { position: absolute; z-index: -1; content: ""; background: rgba(0, 0, 0, .5); width: 200px; height: 200px; left: 5px; top: 5px; -webkit-clip-path: polygon(0 100%, 0 0, 100% 0, 80% 100%); }
<div id="box"> <div id="content"></div> <div id="shadow"></div> </div>
Depending on your use-case, with some clever use of a background image, multiple borders, and/or gradients, you could make the background look between with a fading shadow and what not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With