How to make rectangle with pointed sides?

This question already has an answer here:

  • How to make triangle shape in before a div in pure css? 1 answer
  • How do CSS triangles work? 18 answers

  • The trick is to use the pseudo classes :before and :after . Try it like this:

    .yourButton {
        position: relative;
        width:200px;
        height:40px;
        margin-left:40px;
        color:#FFFFFF;
        background-color:blue;
        text-align:center;
        line-height:40px;
    }
    
    .yourButton:before {
        content:"";
        position: absolute;
        right: 100%;
        top:0px;
        width:0px;
        height:0px;
        border-top:20px solid transparent;
        border-right:40px solid blue;
        border-bottom:20px solid transparent;
    }
    
    .yourButton:after {
        content:"";
        position: absolute;
        left: 100%;
        top:0px;
        width:0px;
        height:0px;
        border-top:20px solid transparent;
        border-left:40px solid blue;
        border-bottom:20px solid transparent;
    }
    

    JsFiddle: http://jsfiddle.net/VpW5x/

    链接地址: http://www.djcxy.com/p/89480.html

    上一篇: 为什么这个CSS代码片段会绘制一个三角形?

    下一篇: 如何制作带有尖角的矩形?