Draw triangle in corner of div

前端 未结 4 1327
夕颜
夕颜 2021-01-02 09:20

I\'d like to draw some kind of triangle in the corner of a div. Because I don\'t want to use "px" I\'d like to achieve the same result also with percentage values.

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-02 10:13

    You can simply rely on background and create the triangle with a linear-gradient above the background-color without extra markup and pseudo-element:

    .container { 
      width: 400px; 
      height: 100px; 
      background: 
       linear-gradient(to top right,transparent 50%,#608A32 0) top right/40px 40px no-repeat,
       black; 
      color: white;
      border-radius: 12px;
      overflow: hidden;
    }

    Related: https://stackoverflow.com/a/49696143/8620333

提交回复
热议问题