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

[分享]css3大于90度的箭头

发布于 2024-11-11 15:17:29
0
36

CSS3中提供了一种方便制作大于90度箭头的方法,可以使用pseudo元素和CSS形状来实现。

.arrow {
  position: relative;
  width: 20px;
  height: 20px;
  background-color: blue;
}

.arrow::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-right: 20px solid blue;
  border-bottom: 10px solid transparent;
  transform: translate(-50%, -50%) rotate(45deg);
}

.arrow::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-left: 20px solid blue;
  border-bottom: 10px solid transparent;
  transform: translate(-50%, -50%) rotate(-45deg);
} 

以上代码实现了一个蓝色的箭头,箭头的大小可以通过修改width和height属性来调整。箭头是通过两个pseudo元素before和after来实现的,具体来说:

before元素是一个梯形,通过border-top,border-right和border-bottom三个属性来实现。其中,border-top和border-bottom的宽度为箭头宽度的一半,border-right的宽度为箭头高度,颜色与箭头一致,形成一个等腰直角三角形。最后通过transform的rotate属性让箭头旋转45度。

after元素同理,宽度和高度与before相同,通过border-top,border-left和border-bottom三个属性来实现。最后通过transform的rotate属性让箭头旋转-45度。

通过以上步骤,我们就可以轻松制作出角度大于90度的箭头了。

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

62849

帖子

14

小组

291

积分

赞助商广告
站长交流