设计图含有斜切角的效果时,我们一般想到的方法是切出四个角为背景,然后用border连起来,这样就能显示出该效果了,那么直接使用css呢?下面就整理css做斜边的效果。
1、方案一:利用linear-gradient
.chamfer{
background: #3b3;
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;
}
</style>
<div class="chamfer" ></div>
2、方案二:利用clip-path
<style>
.base{
width: 300px;height: 300px;
}
.chamfer{
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
);
}
</style>
<div class="chamfer"></div>
css曲线切口角的实现
<style>
.chamfer{
background: #e72;
background: radial-gradient(circle at top left, transparent 15px, #e72 0) top left,
radial-gradient(circle at top right, transparent 15px, #e72 0) top right,
radial-gradient(circle at bottom right, transparent 15px,#e72 0) bottom right,
radial-gradient(circle at bottom left, transparent 15px, #e72 0) bottom left;
background-size: 50% 50%;
background-repeat: no-repeat;
}
</style>
<div class="chamfer"></div>
使用Corner-shape
corner-shape:bevel;
border-radius:10% / 30px;
width:400px;
height: 300px;