Making triangle principle with border

Source: Internet
Author: User
In the front page of the website, sometimes some triangles are used, in addition to the way the image is used, the border property of the CSS can also make the corresponding triangles. So, how to make use of border to achieve the production of triangles?

Let's take a look at the following example:

CSS code:

  width:100px;  height:100px;  Border-top:solid 100px Blue;  Border-left:solid 100px Black;  Border-right:solid 100px Yellow;  Border-bottom:solid 100px Red;

Operation Result:

By displaying the result you can see that the border intersection is formed in 45° evenly, then, when the width of the element is set to 0, what will it look like?

Code:

  width:0;  height:0;  Border-top:solid 100px Blue;  Border-left:solid 100px Black;  Border-right:solid 100px Yellow;  Border-bottom:solid 100px Red;

Operation Result:

In this way, we see four equilateral triangles. So, what do we want to do with a triangle? Imagine what it would be like if we removed an edge.

Code:

  width:0;  height:0;  Border-left:solid 100px Black;  Border-right:solid 100px Yellow;  Border-bottom:solid 100px Red;

Operation Result:

This time, we see three triangles, if we change the black and yellow to transparent, will there be a red equilateral triangle?

Code:

  width:0;  height:0;  Border-left:solid 100px Transparent;  Border-right:solid 100px Transparent;  Border-bottom:solid 100px Red;

Operation Result:

Obviously, the triangle appears. We can try to modify the width of the border or hide the other edges, we can get a different triangle.

Code:

  width:0;  height:0;  Border-left:solid 100px Transparent;  Border-right:solid 100px Transparent;  Border-bottom:solid 50px Red;

Operation Result:

Code:

  width:0;  height:0;  Border-top:solid 100px Transparent;  Border-bottom:solid 100px Transparent;  Border-left:solid 150px Black;

Operation Result:

Code:

  width:0;  height:0;  Border-top:solid 100px Transparent;  Border-left:solid 150px Black;

Operation Result:

Summary: Can be removed by removing one or two borders, set the corresponding border transparent, to achieve the production of triangles, can be varied, more examples are no longer enumerated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.