CSS3中有很多方法可以创建不同种类的三角形,下面我们来介绍几种常用的方法。
/*1. 使用border属性*/
.triangle1{
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid red;
}
/*2. 使用伪元素*/
.triangle2{
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid blue;
position: relative;
}
.triangle2::before{
content: "";
position: absolute;
top: -50px;
left: -50px;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 50px solid blue;
}
/*3. 使用transform属性*/
.triangle3{
width: 100px;
height: 100px;
background-color: green;
transform: rotate(45deg);
} 以上三个例子分别使用了border属性、伪元素和transform属性创建三角形,可以根据需要选择不同的方法来实现。