CSS shadow property isnt showing on an polygon object

Viewed 151

I'm trying to style a div that I shaped with the clip-path: polygon CSS property. I want to give it some shadows so it looks a bit three dimensional.

The problem is that the shadow property doesn't work. When I inspect the element in the browser, the CSS code for shadow is grayed out.

I tried to make the shadow the following ways and none of them worked

  • box-shadow: 0 -2px 2px 0 rgba(0, 0, 0, 0.14), 0 -3px 1px -2px rgba(0, 0, 0, 0.12), 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
  • filter: drop-shadow(0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2));
  • filter: box-shadow 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2);

Here is the HTML code:

 <div id="first" class="row">
            <div class="container-fluid">
...some content inside...
</div>
</div>

And SCSS code:

#first {
    padding-top: 60px;
    padding-bottom: 30px;
    -webkit-box-shadow: 0 -2px 2px 0 rgba(0, 0, 0, 0.14), 0 -3px 1px -2px rgba(0, 0, 0, 0.12), 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
    box-shadow: 0 -2px 2px 0 rgba(0, 0, 0, 0.14), 0 -3px 1px -2px rgba(0, 0, 0, 0.12), 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
    .container-fluid {
      background: red;
      clip-path: polygon(0 0%, 100% 0%, 100% 88%, 0 100%);
    }
  }
2 Answers

Try instead with filter: drop-shadow()

#first {
  padding-top: 60px;
  padding-bottom: 30px;
  filter: drop-shadow(4px 4px 1px rgba(0, 0, 0, 0.3));
}

#first .container-fluid {
  background: red;
  clip-path: polygon(0 0%, 100% 0%, 100% 88%, 0 100%);
}
<div id="first" class="row">
  <div class="container-fluid">
    ...some content inside...
  </div>
</div>

It's working fine. Try changing the h-offset, v-offset, blur spread, color

#first {
  padding-top: 60px;
  padding-bottom: 30px;
  /*-webkit-box-shadow: 0 -9px 9px 0 rgba(0, 0, 0, 0.14), 0 -3px 1px -2px rgba(0, 0, 0, 0.12), 0 -1px 5px 0 rgba(0, 0, 0, 0.2);*/
  /*box-shadow: 0 -2px 2px 0 rgba(0, 0, 0, 0.14), 0 -3px 1px -2px rgba(0, 0, 0, 0.12), 0 -1px 5px 0 rgba(0, 0, 0, 0.2);*/
  -webkit-box-shadow: 5px 10px 18px rgba(0, 0, 0, 0.14), 5px 10px 18px rgba(0, 0, 0, 0.12), 5px 10px 18px rgba(0, 0, 0, 0.2);
  box-shadow: 5px 10px 18px rgba(0, 0, 0, 0.14), 5px 10px 18px rgba(0, 0, 0, 0.12), 5px 10px 18px rgba(0, 0, 0, 0.2);
}
.container-fluid {
  background: red;
  clip-path: polygon(0 0%, 100% 0%, 100% 88%, 0 100%);
}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

<div id="first" class="row">
    <div class="container-fluid">
        ...some content inside...
    </div>
</div>

Related