How To Add Zig Zag Border to a Box contains background image

后端 未结 2 1055
野的像风
野的像风 2020-12-20 03:08

I already find following perfect CSS snippet which creates zip zag border at this link.

.h-zigzag {
    background:
        linear-gradient(-135deg, #33353         


        
2条回答
  •  春和景丽
    2020-12-20 03:29

    You can do that, but you need masking, and as far as I know it is only available in webkit.

    #zigzag {
        width: 600px;
        height: 400px;
        -webkit-mask-image: linear-gradient(0deg, transparent 30px, white 30px), linear-gradient(-135deg, white 15px, transparent 15px), linear-gradient(135deg, white 15px, transparent 15px);
        -webkit-mask-position: left bottom;
        -webkit-mask-repeat: repeat-x;
        -webkit-mask-size: 100% 100%, 30px 30px, 30px 30px;
        background: url("http://placekitten.com/1000/750");
        background-size: cover;
    }
    
    body {
        background-image:  repeating-linear-gradient(20deg, lightgreen, lavender 40px);   
    }

    This works by creating an image that has the zigzag pattern ; and also that has the upper part of the image also transparent. When we use that as a mask, it uses the background where it is transparent.

    I have set the body with a stripes pattern so that it can be seen that the zig zag border is really transparent

    demo

提交回复
热议问题