How to achieve chamfered CSS Border Corners rather than rounded corners?

前端 未结 8 1221
南方客
南方客 2020-12-01 05:47

With the CSS border-radius property I can have a curvy, rounded border corner at the end.

.boxLeft{
             


        
8条回答
  •  醉话见心
    2020-12-01 06:29

    CSS3 Gradients can do the trick:

    Try this, Here's a Fiddle.

    div {
      background: #c00;
      /* fallback */
      background: -moz-linear-gradient(45deg, transparent 10px, #c00 10px), -moz-linear-gradient(135deg, transparent 10px, #c00 10px), -moz-linear-gradient(225deg, transparent 10px, #c00 10px), -moz-linear-gradient(315deg, transparent 10px, #c00 10px);
      background: -o-linear-gradient(45deg, transparent 10px, #c00 10px), -o-linear-gradient(135deg, transparent 10px, #c00 10px), -o-linear-gradient(225deg, transparent 10px, #c00 10px), -o-linear-gradient(315deg, transparent 10px, #c00 10px);
      background: -webkit-linear-gradient(45deg, transparent 10px, #c00 10px), -webkit-linear-gradient(135deg, transparent 10px, #c00 10px), -webkit-linear-gradient(225deg, transparent 10px, #c00 10px), -webkit-linear-gradient(315deg, transparent 10px, #c00 10px);
    }
    
    div {
      background-position: bottom left, bottom right, top right, top left;
      -moz-background-size: 50% 50%;
      -webkit-background-size: 50% 50%;
      background-size: 50% 50%;
      background-repeat: no-repeat;
    }
    
    
    /* Ignore the CSS from this point, it's just to make the demo more presentable */
    
    div {
      float: left;
      width: 50px;
      margin: 15px auto;
      padding: 15px;
      color: white;
      line-height: 1.5;
    }
    Div 1
    Div 2

提交回复
热议问题