DreiDe
DreiDe

Reputation: 139

CSS add shadow to angled div

I have the following code:

.angled{
background-color: red;
height: 120px;
width: 100%;
  -webkit-clip-path: polygon(0 0, 1600px 0, 1600px 53%, 0 100%);
  clip-path: polygon(0 0, 1600px 0, 1600px 53%, 0 100%);
}
<div class="angled"></div>

I want to add an inset shadow to the lower edge of the div. How can I achieve this?

Upvotes: 3

Views: 538

Answers (3)

mindmaster
mindmaster

Reputation: 1888

You can use the filter: drop-shadow. See the docs: https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/drop-shadow

.angeled{
background-color: red;
height: 120px;
width: 100%;
  -webkit-clip-path: polygon(0 0, 1600px 0, 1600px 53%, 0 100%);
  clip-path: polygon(0 0, 1600px 0, 1600px 53%, 0 100%);
 
}

.outer{
   filter: drop-shadow(10px 10px 10px rgba(0,0,0,0.5));
}
<div class="outer">
<div class="angeled">
</div>
</div>

Upvotes: 2

SirPilan
SirPilan

Reputation: 4857

In case you are not bound to using a polygon :)

div.wrapper {
  overflow: hidden;
  height: 150px;
}

div.poly {
  width: 100%;
  height: 100px;
  background-color: #F00;
  box-shadow: 0px 5px 15px rgba(0,0,0,.6);
  transform: rotate(-2deg) scale(1.2);
  transform-origin: 30px 0px;
}
<div class='wrapper'>
  <div class='poly'>
  </div>
</div>

Upvotes: 0

Temani Afif
Temani Afif

Reputation: 273750

You can consider a skewed element as a background where you can easily apply an inset shadow:

.angeled {
  position:relative;
  height: 120px;
  overflow:hidden;
  z-index:0;
}
.angeled::before {
  content:"";
  position:absolute;
  z-index:-1;
  top:-20px;
  left:-20px;
  right:-20px;
  bottom:0;
  transform-origin:left;
  transform:skewY(-3deg);
  background:red;
  box-shadow:0 -2px 20px green inset
}
<div class="angeled"></div>

You can also create this using gradient:

.angeled {
  position:relative;
  height: 120px;
  background:
    linear-gradient(red,red) top/100% 50%,
    linear-gradient(to bottom right,
      red calc(50% - 15px),green calc(50% - 1px),
      transparent 50%) bottom left/150% 50%;
  background-repeat:no-repeat;
}
<div class="angeled"></div>

Upvotes: 3

Related Questions