html css 制作箭头
使用 CSS 制作箭头
纯 CSS 箭头(通过边框实现)
通过调整元素的边框宽度和颜色,可以创建不同方向的箭头:

<div class="arrow"></div>
.arrow {
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #000; /* 箭头颜色 */
}
修改 border-bottom 为其他边框属性可改变箭头方向:

- 上箭头:
border-bottom改为border-top - 左箭头:保留
border-right,其他边框透明 - 右箭头:保留
border-left,其他边框透明
使用伪元素创建更复杂的箭头
.arrow-complex {
position: relative;
width: 100px;
height: 30px;
background-color: #3498db;
}
.arrow-complex::after {
content: "";
position: absolute;
right: -15px;
top: 0;
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 15px solid #3498db;
}
使用 CSS transform 旋转矩形
.arrow-rotate {
width: 20px;
height: 20px;
background-color: #000;
transform: rotate(45deg);
}
SVG 箭头(更灵活可控)
<svg width="100" height="100" viewBox="0 0 100 100">
<path d="M10 50 L90 50 L60 10 L60 90 Z" fill="#000"/>
</svg>
动画箭头
.arrow-animate {
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-top: 15px solid #000;
animation: bounce 1s infinite;
}
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
每种方法适用于不同场景:
- 简单箭头:边框方法最轻量
- 复杂形状:SVG更灵活
- 需要动态效果:CSS动画配合变形
- 需要精确控制:SVG路径最佳






