By hiding certain borders, you can get the triangle effect (as you can see above by making the different portions different colours). transparent is often used as an edge colour to achieve the triangle shape.
Then to hide the two side triangles, set the border-color to transparent. Since the top-border has been effectively deleted, we can set the border-top-color to transparent as well.
/*border-width is border thickness*/#border-demo {background: gray;border-color: yellow blue red green;/*top right bottom left*/border-style: solid;border-width: 25px 25px 25px 25px;/*top right bottom left*/height: 50px;width: 50px;}
It does have a major downside at the moment, one being it's major lack of support, only really being covered within -webkit- browsers and having no support on IE and only very partial in FireFox.
Resources
Here are some useful resources and material to help better understand clip-path and also start creating your own.
.tri {display:inline-block;width:100px;height:100px;background-image:linear-gradient(to bottom right, transparent 49.5%,red 50%),linear-gradient(to bottom left, transparent 49.5%,red 50%);background-size:50.3% 100%; /* I use a value slightly bigger than 50% to avoid having a small gap between both gradient*/background-position:left,right;background-repeat:no-repeat;
animation:change 2s linear infinite alternate;}
@keyframes change {from {width:100px;height:100px;}to {height:50px;width:180px;}}
<div class="tri"></div>
3) equilateral triangle
This one is a bit tricky to handle as we need to keep a relation between the height and width of the gradient. We will have the same triangle as above but we will make the calculation more complex in order to transform the isosceles triangle to an equilateral one.
To make it easy, we will consider that the width of our div is known and the height is big enough to be able to draw our triangle inside (height >= width).
We have our two gradient g1 and g2, the blue line is the width of the divw and each gradient will have 50% of it (w/2) and each side of the triangle sould be equal to w. The green line is the height of both gradient hg and we can easily obtain the formula below:
(w/2)² + hg² = w² ---> hg = (sqrt(3)/2) * w ---> hg = 0.866 * w
We can rely on calc() in order to do our calculation and to obtain the needed result:
But what if we want to define a value for each side? We simply need to do calculation again!
Let's define hg1 and hg2 as the height of our gradient (both are equal to the red line) then wg1 and wg2 as the width of our gradient (wg1 + wg2 = a). I will not going to detail the calculation but at then end we will have: