直接用css生成三角形的问题

方法一:

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8" />
<title></title>
<style>
*{margin:0;padding:0;}
.text {
border-right: 50px solid transparent;
border-top: 50px solid #aaa;
height: 0;
left: 0;
position: absolute;
top: 0;
0;
}
</style>
</head>
<body>
<div class="text"></div>
</body>
</html>

方法二:

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8" />
<title></title>
<style>
*{margin:0;padding:0;}
.text {
100px;
height: 100px;
position: absolute;
left: 0;
top: 0px;
margin-left: -50px;
margin-top: -50px;
background: red;
transform: rotate(45deg);
}
}
</style>
</head>
<body>
<div class="text"></div>
</body>
</html>

总结:这2种方法都可以实现效果

原文地址:https://www.cnblogs.com/ll-taj/p/5287221.html