html + css write triangle (2)

First we look at the following piece of code in the page renderings:


<!doctype html>
<html>
 
	<head>
		<meta charset="utf-8">
		<title>三角形</title>
		<style>
			.triangle{
				width: 0;
				height: 0;
				border: 300px solid red;
				border-top-color: red;
				border-bottom-color: blue;
				border-left-color: pink;
				border-right-color: yellow;
			}
		</style>
	</head>
	<body>
		<div class="triangle"></div>
	</body>
</html>

Here Insert Picture Description
See the renderings, we will probably know how to write a triangle, we can set the border-bottom half none at this box, there is no

border-top: none;

The effect is as follows:
Here Insert Picture Description
Then we will border-left and border-right color to be transparent, so that only the border-bottom

<!doctype html>
<html>
 
	<head>
		<meta charset="utf-8">
		<title>三角形</title>
		<style>
			.triangle{
				width: 0;
				height: 0;
				border: 100px solid transparent;
				border-top-color: black;
				border-bottom: none;
				border-left-color: transparent;
				border-right-color: transparent;
			}
		</style>
	</head>
	<body>
		<div class="triangle"></div>
	</body>
</html>

The effect is as follows:
Here Insert Picture Description

Well, we now complete the preparation of the triangle, there are other similar triangles, replicability, can do it this way, here I will not describe. Finally, I wish you all happy to learn.

Guess you like

Origin blog.csdn.net/qq_42363090/article/details/93473069