css制作向左箭头
使用 CSS 边框制作向左箭头
通过设置元素的边框属性,可以利用透明边框和实色边框的组合创建箭头效果。将元素的宽度和高度设为 0,通过调整边框宽度和颜色实现箭头方向。
.arrow-left {
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right: 10px solid #000; /* 箭头颜色 */
}
使用伪元素旋转制作箭头
通过伪元素(如 ::before 或 ::after)结合旋转和边框属性生成箭头。这种方法适合需要更复杂样式或动画的场景。

.arrow-left {
position: relative;
width: 20px;
height: 20px;
}
.arrow-left::before {
content: "";
position: absolute;
width: 10px;
height: 10px;
border-left: 2px solid #000;
border-bottom: 2px solid #000;
transform: rotate(45deg);
left: 5px;
top: 3px;
}
使用 SVG 内联方式
SVG 提供更灵活的箭头绘制方式,适合需要高精度或多色箭头的场景。通过 path 元素定义箭头路径。

<svg width="20" height="20" viewBox="0 0 20 20">
<path d="M14 5 L6 10 L14 15" stroke="#000" stroke-width="2" fill="none" />
</svg>
使用 Unicode 符号
直接使用 Unicode 中的箭头符号,结合 CSS 调整大小和颜色。这种方法简单但样式有限。
.arrow-left {
font-size: 24px;
color: #000;
}
<span class="arrow-left">←</span>
使用 CSS 渐变背景
通过线性渐变或锥形渐变绘制箭头形状,适合需要渐变色彩或背景融合的场景。
.arrow-left {
width: 20px;
height: 20px;
background: linear-gradient(to bottom right, transparent 45%, #000 45%, #000 55%, transparent 55%);
transform: rotate(45deg);
}






