css制作箭头详解
使用 CSS 制作箭头
使用边框实现三角形箭头
通过设置元素的边框宽度和颜色,并将宽度设为0,可以创建三角形箭头。
.arrow {
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #000;
}
调整 border-left、border-right 和 border-bottom 的值可以改变箭头的大小和方向。

使用旋转伪元素制作箭头
通过旋转伪元素可以创建更复杂的箭头形状。
.arrow {
position: relative;
width: 100px;
height: 20px;
background: #000;
}
.arrow::after {
content: '';
position: absolute;
right: -10px;
top: 0;
width: 0;
height: 0;
border-left: 10px solid #000;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
}
使用 SVG 制作箭头
SVG 提供了更灵活的箭头绘制方式,可以通过路径定义箭头的形状。

<svg width="100" height="50" viewBox="0 0 100 50">
<path d="M0,25 L80,25 L70,15 L100,25 L70,35 L80,25 Z" fill="#000" />
</svg>
使用 CSS 渐变制作箭头
通过线性渐变可以创建带有箭头的背景效果。
.arrow {
width: 100px;
height: 50px;
background: linear-gradient(to right, #000 80%, transparent 80%),
linear-gradient(to bottom right, transparent 50%, #000 50%) 80% 0,
linear-gradient(to top right, transparent 50%, #000 50%) 80% 100%;
background-size: 80% 100%, 20% 50%, 20% 50%;
background-repeat: no-repeat;
}
使用 clip-path 制作箭头
clip-path 属性可以裁剪元素为任意形状,包括箭头。
.arrow {
width: 100px;
height: 50px;
background: #000;
clip-path: polygon(0% 50%, 80% 50%, 80% 0%, 100% 50%, 80% 100%, 80% 50%);
}
注意事项
- 边框实现的箭头在不同浏览器中可能有细微差异。
- SVG 箭头具有更好的可缩放性,适合响应式设计。
clip-path的浏览器兼容性需要考虑,部分旧版本浏览器可能不支持。- 渐变实现的箭头可能需要调整参数以达到理想效果。






