首先创建一个div元素,设置div的width和height为0;
只用 边框 来填充,边框样式设置为实线“solid”;
然后顶部边框设置颜色,剩下的三个边框的颜色设置为透明“transparent”值即可。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>css三角制作</title>
<style>
/* css做三角形的方法:首先创建一个div元素,设置div的width和height为0,只用边框宽来填充,边框样式设置为实线“solid”;然后顶部边框设置颜色,剩下的三个边框的颜色设置为透明“transparent”值即可。 */
.triangle {
border: 50px solid;
width: 0px;
height: 0px;
border-color: aqua transparent transparent transparent;
}
</style>
</head>
<body>
<div class="triangle"></div>
</body>
</html>