Principle analysis of the simplest way to implement triangles in css

Implementation principle analysis

A rectangle with no width and height can be composed of four sides. Then the shape of these four sides is a triangle. If the color of three of the sides is set to transparent, then only one triangle is left, which is the final desired triangle.

Rendering:
Insert image description here

Implement triangle code

Draw a triangle with color pink:

width: 0;
height: 0;
border-top: 50px solid pink;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 50px solid transparent;

Case:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>画三角形</title>
		<style>
			.box {
				width: 0;
				height: 0;
				border-top: 50px solid pink;
				border-left: 50px solid transparent;
				border-right: 50px solid transparent;
				border-bottom: 50px solid transparent;
			}
		</style>
	</head>
	<body>
		<div class="box"></div>
	</body>
</html>

Effect:
Insert image description here

Application scenarios

  • Similar to WeChat chat bubble

Guess you like

Origin blog.csdn.net/qq_42961150/article/details/125597521