Search code examples
htmlcssangularjsbox-shadowangular-foundation

Box shadow to triangle created using css


I have the following plunker where I have created a triangle using CSS.

CSS:

.triangle {
    border: inset 6px;
    content: "";
    display: block;
    height: 0;
    width: 0;
    border-color: transparent transparent red transparent;
    border-bottom-style: solid;
    position: absolute;
    top: 50px;
    left: 50px;
    z-index: 89;
}

HTML:

<div class="triangle">
</div>

In my AngularJS project, this triangle is created when I call a dropdown directive as defined here.

The problem is that I want to give this triangle and the dropdown popup a box shadow. I am able to apply it on the popup (which is essentially just a 'ul' list) but I am struggling with the triangle. How can I apply box shadow to the triangle?


Solution

  • .triangle {
      position: relative;
      margin: 0;
      box-sizing: border-box;
      background: red;
      box-shadow: 0px 3px 3px 0 rgba(0, 0, 0, 0.4);
    }
    .triangle::after {
      content: "";
      position: absolute;
      top: 50px;
      left: 50px;
      width: 0;
      height: 0;
      box-sizing: border-box;
      border: 6px solid black;
      border-color: transparent transparent red red;
      transform-origin: 0 0;
      transform: rotate(-45deg);
      box-shadow: -3px 3px 3px 0 rgba(0, 0, 0, 0.4);
    }
    <!DOCTYPE html>
    <html>
    
      <head>
        <link rel="stylesheet" href="style.css">
        <script src="script.js"></script>
      </head>
    
      <body>
        <div class="triangle">
          
        </div>
      </body>
    
    </html>

    Here is the HTML and CSS to create the desired effect.