Search code examples
cssshadowborder-box

css3 shadow box top and left + right for half height


I am trying to set css shadow for top part and also for left and right but with reduced height. I am familiar with blur/radius, but I want the shadow be really short. picture from wix template (cant upload yet, I am sorry)

Can somebody please help me? The last chance I see, I will probably use border-image but I want to avoide it, if possible. Thanks for every suggestion


Solution

  • One posibility, using a pseudo rotated with perspective and dimensioned to only half the height:

    .test {
      width: 200px;
      height: 200px;
      margin: 10px;
      border: solid 1px red;
      position: relative;
      background-color: white;
    }
    
    .test:after {
      content: "";
      position: absolute;
      top: 0px;
      right: 0px;
      height: 50%;
      left: 0px;
      box-shadow: 0px 0px 15px 2px black;
      transform: perspective(400px) rotateX(-10deg);
      transform-origin: center top;
      z-index: -1;
    }
    <div class="test"></div>