css边框斜角

发布时间 2023-06-14 17:41:15作者: 一江春水向东刘小姐

为实现下面图形形状

<style>
.box{width:200px;height:100px;}
</style>
<div class="box" ></div>

1、利用linear-gradient

.box{
    background: linear-gradient(135deg, transparent 15px, #3b3 0) top left,
      linear-gradient(-135deg, transparent 15px, #3b3 0) top right,
      linear-gradient(-45deg, transparent 15px, #3b3 0) bottom right,
      linear-gradient(45deg, transparent 15px, #3b3 0) bottom left;  
      background-size: 50% 50%;
      background-repeat: no-repeat;
}

2、利用clip-path

.chamfer{
      width: 200px;
      height: 100px;
  
      background: #009EEB; 
      clip-path: polygon( 20px 0, calc(100% - 20px) 0, 100% 20px, 100% calc(100% - 20px), calc(100% - 20px) 100%, 20px 100%, 0 calc(100% - 20px), 0 20px);
  }