css3知识汇总:切角

1.使用渐变

因为渐变可以接受一个角度,比如45deg作为方向,而且色标的位置信息也可以是绝对的长度值,不受容器尺寸的影响。把一个透明色标放在切角处,然后在相同位置设置另一个色标,并且颜色设置为想要的背景色。

4个切角,写几个 linear-gradient就是几个切角

div{

    width:300px;

    height: 200px;

    background-color: #58a;/*回退机制*/

    background:

        linear-gradient(-45deg, transparent 15px, #58a 0) bottom right,

        linear-gradient(45deg, transparent 15px, #58a 0) bottom left,

        linear-gradient(-135deg, transparent 15px, #58a 0) top right,

        linear-gradient(135deg, transparent 15px, #58a 0) top left;

    background-size: 50% 50%;

    background-repeat: no-repeat;

}

transparent改为red


background-size:45% 45%

2.使用clip-path

div{

    width:300px;

    height:200px;

    background: #58a;

    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.使用corner-shape

div{

    width:300px;

    height:200px;

    background: #58a;

    corner-shape:bevel;

    border-radius:10% / 30px;

    width:400px;

    height: 300px;

}

注:目前此方法还在测试中,还没有浏览器支持

【弧形切角(内凹圆角)】

div{

    width:300px;

    height:200px;

    background-color: #58a;/*回退机制*/

    background:

        radial-gradient(circle at top left, transparent 15px, #58a 0) top left,

        radial-gradient(circle at top right, transparent 15px, #58a 0) top right,

        radial-gradient(circle at bottom right, transparent 15px, #58a 0) bottom right,

        radial-gradient(circle at bottom left, transparent 15px, #58a 0) bottom left;

    background-size: 50% 50%;

    background-repeat: no-repeat;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容

  • 渐变组合:透过彼此的透明区域显现 网格图案--桌布 div{ width: 30em; height:30em...
    0清婉0阅读 283评论 0 1
  • 【半透明边框】 body{background-color:green}img{ border:10px sol...
    0清婉0阅读 277评论 0 1
  • 文字阴影 text-shadow: 5px 5px 5px #000; text-shadow: 水平位置 垂直位...
    YGAM阅读 316评论 0 0
  • 1、垂直对齐 如果你用CSS,则你会有困惑:我该怎么垂直对齐容器中的元素?现在,利用CSS3的Transform,...
    kiddings阅读 3,207评论 0 11
  • shkdsnks 一、背景与边 1、半途明边框 当页面中有div,css样式如下时: width: 100px;h...
    LittlehorseX阅读 531评论 0 0