How can I create Triangle shape clip mask using CSS

前端 未结 4 1560
面向向阳花
面向向阳花 2021-01-18 18:45

I want to create triangle as shown in image. Does someone know how to achieve the effect?

\"enter

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 19:34

    Here is a fiddle that should solve your problem. I used :before and :after on a container to place two squares over the container with borders to create the arrows. You can mess with the border colors and widths to get the arrows how you want them (just remember the inside borders have to be the same weight to make an symmetrical triangle).

    http://jsfiddle.net/Smzmn/

    .hero {
        background: url(http://d.pr/i/eqn9+);
        height: 200px;
        position: relative;
    }
    
    .hero:before, .hero:after {
        box-sizing: border-box;
        content: " ";
        position: absolute;
        top:0;
        display: block;
        width: 50%;
        height: 100%;
        border: 30px solid orange;
        border-bottom-color: pink;
    }
    
    .hero:before {
        left: 0;
        border-right: 20px solid transparent;
        border-left: 0;
    }
    
    .hero:after {
        right: 0;
        border-left: 20px solid transparent;
        border-right: 0;
    }
    

提交回复
热议问题