19
Sep
Learn how to do CSS triangle shape work
Start with a basic square and borders. Each border will be given a different color so we can tell them apart:
.triangle { border-color: yellow blue red green; border-style: solid; border-width: 200px 200px 200px 200px; height: 0px; width: 0px; }
which gives you this:
More shapes
But there’s no need for the top border, so set its width to 0px. Now our border-bottom of 200px will make our triangle 200px tall.
.triangle { border-color: yellow blue red green; border-style: solid; border-width: 0px 200px 200px 200px; height: 0px; width: 0px; }
and we will get this:
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.
.triangle { border-color: transparent transparent red transparent; border-style: solid; border-width: 0px 200px 200px 200px; height: 0px; width: 0px; }
finally we get this: