参考代码:
?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>三角形制作</title>
<style>
.triangle1 {
width: 0;
height: 0;
border-top: 50px solid transparent;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 50px solid red;
/* transform: rotate(45deg); */
}
.triangle2 {
position: relative;
width: 100px;
height: 100px;
}
.triangle2::before {
content: "";
position: absolute;
top: 0;
left: 0;
border-width: 0px 100px 100px 0px;
border-style: solid;
border-color: transparent red transparent transparent;
}
.triangle4 {
width: 100px;
height: 100px;
background-color: red;
clip-path: polygon(0 0, 100% 0, 50% 100%);
}
</style>
</head>
<body>
<h2>方法1</h2>
<div class="triangle1"></div>
<h2>方法2</h2>
<div class="triangle2"></div>
<h2>方法3</h2>
<div>
方法1的CSS添加:<br />
transform: rotate(45deg);
</div>
<h2>方法4</h2>
<div class="triangle4"></div>
</body>
</html>