Skip to content
Related Articles

Related Articles

Improve Article

How to add Box-Shadow to The Clip-Path Object ?

  • Last Updated : 18 Apr, 2021

As we all know that we can apply the shadow using the Box-Shadow attribute of CSS, but it is not valid if we apply it on the 
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.

HTML Code:

  1. Firstly, create an HTML file (index.html).
  2. Now after the creation of our HTML file, we are going to give a title to our webpage using the 
    <title> tag. It should be placed between the <head> tag.
  3. Then we link the CSS file that provides all the background images to our HTML. This is also placed in 
    between the <head> tag.
  4. Coming to the body section of our HTML code.
    1. Firstly, create a main div as the main box.
    2. In that div, add 1 more div to add the clip-path object.

index.html




<!DOCTYPE html>
<html lang="en">
    
<head>
  <title>Document</title>
  <link rel="stylesheet" href="style.css">
</head>
    
<body>
  <div class="main_box">
      <div class="img"></div>
  </div>    
</body>
    
</html>

CSS Code: The following is the content for the “style.css” file used in the above code. CSS is used to give different types of animations and
effects to our HTML page so that it looks interactive to all the users. Consider the following points:



  • Restore all the browser effects.
  • Use classes and IDs to give effects to HTML elements.

Style.css




.main_box{
  filter: drop-shadow(1.25em .75em 0px rgb(150, 223, 150));
 }
   
.img{
  border-radius: 1em;
  width: 15em;
  height: 15em;
  clip-path: polygon(75% 0%, 100% 50%,75% 100%,0% 100%,0% 0%);
  background-color: green;
 }

Complete Code: Here we will combine the above two section in to one.

HTML




<!DOCTYPE html>
<html lang="en">
    
<head>
  <style>
    .main_box{
        filter: drop-shadow(1.25em .75em 0px rgb(150, 223, 150));
    }
  
    .img{
        border-radius: 1em;
        width: 15em;
        height: 15em;
        clip-path: polygon(75% 0%, 100% 50%,75% 100%,0% 100%,0% 0%);
        background-color: green;
    }
  </style>
</head>
    
<body>
    <div class="main_box">
        <div class="img"></div>
    </div>    
</body>
    
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :