Making jagged triangle border in CSS

前端 未结 5 500
梦谈多话
梦谈多话 2020-12-01 04:43

I have a shape with an edge like this in Photoshop:

\"image\"

Is it possible to make the repeated trian

5条回答
  •  自闭症患者
    2020-12-01 05:09

    You can use css3 gradients to create a zig-zag patterned background, use the after css pseudo to apply it like a border.

    .header{
        color: white;
        background-color: #2B3A48;
        text-align: center;
    }
    .header:after {
        content: " ";
        display: block;
        position: relative;
        top: 0px;
        left: 0px;
        width: 100%;
        height: 36px;
        background: linear-gradient(#2B3A48 0%, transparent 0%), linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 linear-gradient(45deg, #272220 33.33%, #2B3A48 33.33%) 0 0%;
        background: -webkit-linear-gradient(#2B3A48 0%, transparent 0%), -webkit-linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 -webkit-linear-gradient(45deg, #272220 33.33%, #2B3A48 33.33%) 0 0%;
        background: -o-linear-gradient(#2B3A48 0%, transparent 0%), -o-linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 -o-linear-gradient(45deg, #272220 33.33%, #2B3A48 33.33%) 0 0%;
        background: -moz-linear-gradient(#2B3A48 0%, transparent 0%), -moz-linear-gradient(135deg, #272220 33.33%, transparent 33.33%) 0 0%, #272220 -moz-linear-gradient(45deg, #272220 33.33%, #2B3A48 33.33%) 0 0%;
        background-repeat: repeat-x;
        background-size: 0px 100%, 9px 27px, 9px 27px;
    }

    This is a header

    Source: CSS Zigzag Border with a Textured Background

    JSFiddle: http://jsfiddle.net/kA4zK/

提交回复
热议问题