廢話不多說,先上效果圖
再上代碼
<!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>
沒看懂的話接着往下看,看懂了就可以退出了
1. 設置div有一定寬高,四邊設置邊框
.triangle{
width: 50px;
height: 50px;
border-top: 200px solid #00a497;
border-bottom: 200px solid #cc7eb1;
border-left: 200px solid #165e83;
border-right: 200px solid #c85179;
}
效果圖如下
2. 設置div寬高爲0,四邊設置邊框寬度爲200px
.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;
}
效果如下:
3. 接下來div寬高仍爲0,去掉border-top
.triangle{
width: 0px;
height: 0px;
border-bottom: 200px solid #cc7eb1;
border-left: 200px solid #165e83;
border-right: 200px solid #c85179;
}
效果圖
4. 最後發現,只將border-bottom設置顏色,左右邊框透明,既可得到三角形
.triangle{
width: 0px;
height: 0px;
border-bottom: 200px solid #cc7eb1;
border-left: 200px solid transparent;
border-right: 200px solid transparent;
}