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: