CSS Triangle

There are many resources out there about how to make a CSS triangle, so I’ll just keep this brief and reference the one I used.

Basically, its just a box with height and width of zero, and we use the border to create the triangle. If we use the below code, we will create a box made from four triangles (one from each border).

.arrow-right {
  width: 0px;
  height: 0px;
  border-top: 60px solid black;
  border-bottom: 60px solid black;
  border-left: 60px solid green;
  border-right: 60px solid blue;
}

This creates this shape:
Screen Shot 2015-03-27 at 7.40.05 AM

Now to just make a single triangle, we make three of them transpara

.arrow-right {
  width: 0; 
  height: 0; 
  border-top: 60px solid transparent;
  border-bottom: 60px solid transparent;
  border-left: 60px solid green;
  border-right: 60px solid transparent;
}

which makes:

Screen Shot 2015-03-27 at 7.43.38 AM

Now we can remove the borders that are transparent, but it will change the shape of the triangle. You can play around by removing various borders and see if you like the shape of the triangle. Also, playing with the size or number of pixels in all four sides of the border will adjust the shape of the triangle.

Credit here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s