使用CSS画一个三角形
2021-08-17 本文已影响0人
小李不小
代码+效果图
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
/* css3绘制三角形 */
.triangle{
width: 0px; /*设置宽高为0,所以div的内容为空,从才能形成三角形尖角*/
height: 0px;
border-bottom: 200px solid #00a3af;
border-left: 200px solid transparent; /*transparent 表示透明*/
border-right: 200px solid transparent;
}
</style>
</head>
<body>
<div class="triangle"></div>
</body>
</html>
image.png
实现步骤 - 还是不理解的小伙伴可以看下面
1. 首先画一个 四边形
<div class="triangle"></div>
.triangle{
width: 0px;
height: 0px;
border-top: 200px solid #00a497;
border-bottom: 200px solid #cc7eb1;
border-left: 200px solid #165e83;
border-right: 200px solid #c85179;
}
image.png
2. 去掉border-top,三角顶部就不见了
<div class="triangle"></div>
.triangle{
width: 0px;
height: 0px;
border-bottom: 200px solid #cc7eb1;
border-left: 200px solid transparent;
border-right: 200px solid transparent;
}
image.png
2. 最后发现,只将border-bottom设置颜色,左右边框透明,既可得到三角形
<div class="triangle"></div>
.triangle{
width: 0px;
height: 0px;
border-bottom: 200px solid #cc7eb1;
border-left: 200px solid transparent;
border-right: 200px solid transparent;
}
//transparent 设置为透明的意思