Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create Triangle shape clip mask using CSS

Tags:

html

css

geometry

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

enter image description here

like image 903
Rahul Vyas Avatar asked Jun 20 '14 12:06

Rahul Vyas


Video Answer


1 Answers

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;
}
like image 127
Travis L Avatar answered Oct 19 '22 19:10

Travis L