Draw a triangle using CSS border and CSS border

Source: Internet
Author: User

Draw a triangle using CSS border and CSS border

Using border to draw triangles is actually an odd trick.

Using a border feature: When the width and height of an element are 0, set the width for border (at least two adjacent borders are set ), border will support this element.

When the width of the four borders is set at the same time, the four sides are finally merged into a vertex in the center of the element.

 

Therefore, when we set a border for an element with a width and height, the four borders are connected in the form of diagonal lines rather than right-angle stitching,

 

 

Therefore, if the width and height are not set, four triangles of different colors and different directions can be obtained when different colors are set for the four borders:

 

 

When you want to create a triangle, you cannot set a single border. When you only set a border, it is only a line with only width and no height and cannot be displayed on the page;

Therefore, you need to set four borders at the same time or set the width of two adjacent borders. You only need to add a color to one of the borders:

Set four sides:

 

Set only two adjacent edges:

 

 

 

 

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.