渐变实现切角
两个切角
<body>
<div class="box"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<div class="box5"></div>
</body>
div{
margin: 50px;
width: 200px;
height: 100px;
}
.box{
background-image: linear-gradient(-45deg,transparent 10px,lightskyblue 0);
background-size: 50% 100%;
background-position: right;
}
.box2{
background-image: linear-gradient(45deg,transparent 10px,lightskyblue 0);
background-size: 50% 100%;
background-position: left;
}
.box3{
background-image: linear-gradient(-45deg, transparent 10px, lightskyblue 0);
background-size: 50% 100%;
background-position: right;
background-repeat: no-repeat;
}
.box4{
background-image: linear-gradient(45deg,transparent 10px, lightskyblue 0);
background-size: 50% 100%;
background-position: left;
background-repeat: no-repeat;
}
.box5{
/* background-image: linear-gradient( 45deg,transparent 10px,lightskyblue 0),
linear-gradient(-45deg,transparent 10px,lightskyblue 0);
background-size: 50% 100% , 50% 100%;
background-position: left,right;
background-repeat: no-repeat, no-repeat; */
background: linear-gradient( 45deg,transparent 10px,lightskyblue 0) left/50% 100% no-repeat,
linear-gradient(-45deg,transparent 10px, lightskyblue 0) right/50% 100% no-repeat;
}
background简写中,注意,background-position/background-size
四个切角
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<div class="box"></div>
</body>
div{
width: 200px;
height: 100px;
border: 1px solid lightgray;
margin: 5px;
}
.box1{
background-image: linear-gradient(135deg,transparent 10px,lightskyblue 0);
background-size: 50% 50%;
background-position: left top;
background-repeat: no-repeat;
}
.box2{
background-image: linear-gradient(-135deg,transparent 10px,lightskyblue 0);
background-size: 50% 50%;
background-position: right top;
background-repeat: no-repeat;
}
.box3{
background-image: linear-gradient(45deg,transparent 10px,lightskyblue 0);
background-size: 50% 50%;
background-position: left bottom;
background-repeat: no-repeat;
}
.box4{
background-image: linear-gradient(-45deg,transparent 10px,lightskyblue 0);
background-size: 50% 50%;
background-position: right bottom;
background-repeat: no-repeat;
}
.box{
background:linear-gradient(135deg,transparent 10px,lightskyblue 0) left top,
linear-gradient(-135deg,transparent 10px,lightskyblue 0) right top,
linear-gradient(-45deg,transparent 10px,lightskyblue 0) right bottom,
linear-gradient(45deg,transparent 10px,lightskyblue 0) left bottom;
background-size: 50% 50%;
background-repeat: no-repeat;
}
圆弧切角
<body>
<div class="box"></div>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<div class="box5"></div>
<div class="box6"></div>
</body>
div{
margin: 5px;
width: 200px;
height: 100px;
border: 1px solid lightgray;
}
.box{
background-image: radial-gradient(transparent 50px,lightskyblue 0);
}
.box1{
background-image: radial-gradient(circle,transparent 50px,lightskyblue 0);
}
.box2{
background-image: radial-gradient(circle at left top,transparent 50px,lightskyblue 0);
}
.box3{
background-image: radial-gradient(circle at right top,transparent 50px,lightskyblue 0) ;
}
.box4{
background-image: radial-gradient(circle at right bottom,transparent 50px,lightskyblue 0 );
}
.box5{
background-image: radial-gradient(circle at left bottom,transparent 50px,lightskyblue 0);
}
.box6{
background: radial-gradient(circle at left top,transparent 30px,lightskyblue 0) left top,
radial-gradient(circle at right top,transparent 30px,lightskyblue 0) right top,
radial-gradient(circle at right bottom,transparent 30px,lightskyblue 0) right bottom,
radial-gradient(circle at left bottom,transparent 30px,lightskyblue 0) left bottom;
background-size: 50% 50%;
background-repeat: no-repeat;
}
SVG+border-image实现切角
<body>
<svg xmlns="http:/www.w3.org/2000/svg" width="30" height="30" fill="lightskyblue">
<polygon points="10,0 20,0 30,10 30,20 20,30 10,30 0,20 0,10"/>
</svg>
</body>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</body>
div{
margin: 5px;
}
.box1{
width: 200px;
height: 100px;
background-color: lightgoldenrodyellow;
border: 20px solid transparent;
border-image: url('data:image/svg+xml,\
<svg xmlns="http://www.w3.org/2000/svg"\
width="3" height="3" fill="lightskyblue">\
<polygon points="1,0 2,0 3,1 3,2 2,3 1,3 0,2 0,1"/>\
</svg>');
}
.box2{
width: 200px;
height: 100px;
background-color: lightgoldenrodyellow;
border: 20px solid transparent;
border-image: url('data:image/svg+xml,\
<svg xmlns="http://www.w3.org/2000/svg"\
width="3" height="3" fill="lightskyblue">\
<polygon points="1,0 2,0 3,1 3,2 2,3 1,3 0,2 0,1"/>\
</svg>');
border-image-slice:1;
}
.box3{
width: 200px;
height: 100px;
background-color: lightskyblue;
background-clip: content-box;
border: 20px solid lightskyblue;
border-image: url('data:image/svg+xml,\
<svg xmlns="http://www.w3.org/2000/svg"\
width="3" height="3" fill="lightskyblue">\
<polygon points="1,0 2,0 3,1 3,2 2,3 1,3 0,2 0,1"/>\
</svg>');
border-image-slice:1;
}
clip-path实现切角
<body>
<div class="box"></div>
</body>
.box{
width: 200px;
height: 100px;
background-color: lightskyblue;
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);
}