Use css to draw triangles and css to draw triangles

Source: Internet
Author: User
Tags transparent color

Use css to draw triangles and css to draw triangles

I saw some questions asking how to draw triangles with css.

As we all know, many images can be split into triangles, so a lot of interesting shapes can be drawn by drawing triangles.

 

The principle of drawing a triangle is to adjust the width, line style, and color of the border in four directions.

If you adjust the width to a large value and change the color in different directions, you can find that the border of the box model is the same as the four trapezoid lines.

At this time, if the height and width inside the box model are adjusted to 0px, the triangle is formed.

1 border: 100px solid transparent // border 100px, solid line, transparent color, the following three lines of code are equivalent to this sentence 2 border-width: 15px; // border-width indicates border3 border-style: solid in all directions; 4 border-color: transparent;

If you understand the principle, you should be able to write your own code now.

1 width: 0; 2 height: 0; 3 border-left: 50px solid transparent; // left width: 50px, solid line, transparent color: 4 border-right: 50px solid transparent; // The right side is the same as 5 border-top: 100px solid red; // The top is Px in width, solid line, and red.

The above code can generate a downward triangle. As shown in (I replaced the color on the right for ease of understanding)

From this we can see that we need three borders to generate a triangle.

The height of the left and right sides of the border determines the height of the triangle.

The triangle height is determined by the Border width.

So how to generate a triangle like this pointing to the lower right or lower left?

I believe you can see from the figure above.

We only need two borders.

1     width: 0;2     height: 0;3     border-top: 100px solid red;4     border-right: 100px solid transparent;

This code generates a triangle pointing to the bottom left, with the bottom and height 100px.

Remember border-width.

It can define the width of the four borders with a single code.

 

Reprinted please contact

Related Article

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.