首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[分享]css3各种三角形

发布于 2024-11-11 14:23:13
0
61

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属性创建三角形,可以根据需要选择不同的方法来实现。

评论
一个月内的热帖推荐
91云脑
Lv.1普通用户

62849

帖子

14

小组

291

积分

赞助商广告
站长交流