【css】实现切角

渐变实现切角
两个切角
<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);
}

在这里插入图片描述

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值