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:
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:
Application scenarios
- Similar to WeChat chat bubble