思路是使用border边框来实现三角形的样式
1.div盒子宽高设为0,用边框填满盒子区域
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
width:0;
height:0;
border: 100px solid #000000;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
浏览器中展示效果如下:
2.分别设置4个边框的颜色
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
width:0;
height:0;
border-top:100px solid #000000;
border-right:100px solid yellow;
border-bottom:100px solid green;
border-left:100px solid pink;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
浏览器中展示效果如下:
3.将三个边框的颜色更改为透明色,三角形显示出来
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
width:0;
height:0;
border-top:100px solid #000000;
border-right:100px solid transparent;
border-bottom:100px solid transparent;
border-left:100px solid transparent;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
浏览器中展示效果如下: