How can I correctly add a shadow and a gradient to my triangular shape?

前端 未结 5 777
暗喜
暗喜 2021-01-01 17:59

I want to make the following design:

I tried with :after and :before but it does not work. Here’s my current code:

5条回答
  •  粉色の甜心
    2021-01-01 18:26

    If you change your CSS to the following minor changes, then you can achieve the result that you have expected:

    .design {
      background: #ea053a;
      display: inline-block;
      height: 100px;
      margin-left: 33px;
      margin-right: 40px;
      position: relative;
      width: 180px;
    }
    
    .design:before {
      border-top: 43px solid #ea053a;
      border-left: 90px solid transparent;
      border-right: 90px solid transparent;
      margin-right: 40px;
      content: "";
      height: 0;
      left: 0;
      position: absolute;
      top: 0px;
      margin-top: 100px;
      width: 0;
    }
    

    Here is the working of the above CSS:

    .design {
      background: #ea053a;
      display: inline-block;
      height: 100px;
      margin-left: 33px;
      margin-right: 40px;
      position: relative;
      width: 180px;
    }
    
    .design:before {
      border-top: 43px solid #ea053a;
      border-left: 90px solid transparent;
      border-right: 90px solid transparent;
      margin-right: 40px;
      content: "";
      height: 0;
      left: 0;
      position: absolute;
      top: 0px;
      margin-top: 100px;
      width: 0;
    }

    Hope this was helpful.

    My Fiddle

提交回复
热议问题