html边框有箭头,css 画带边框的箭头的问题

本文探讨了如何使用CSS精细绘制一个带边框的箭头,通过组合长方形和三角形,以及调整透明度和边宽来解决放大后出现的缺陷。作者分享了解决方案和优化过程,适合前端开发者学习CSS布局技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我想要用css画一个如下图的箭头,带边框

bV2oAx?w=204&h=76

思路很简单,用一个带坐上下边框的长方形,拼一个灰色的三角形,然后在用一个白色的三角形遮挡掉灰色三角形的主题部分从而形成一个三角形的边框

以下是css实现

.first-step {

height: 23px;

width: 80px;

line-height: 23px;

border-left: 1px solid #e5e5e5;

border-top: 1px solid #e5e5e5;

border-bottom: 1px solid #e5e5e5;

display: inline-block;

text-align: center;

position: relative;

}

.first-step:after {

width: 0;

height: 0;

content: '';

border-left: 14px solid #e5e5e5;

/*border-right: 14px solid transparent;*/

border-top: 12.5px solid transparent;

border-bottom: 12.5px solid transparent;

position: absolute;

right: -14px;

top: -1px;

z-index: 2;

}

.first-step:before {

width: 0;

height: 0;

content: '';

border-left: 14px solid white;

border-top: 12.5px solid transparent;

border-bottom: 12.5px solid transparent;

position: absolute;

right: -12px;

top: -1px;

z-index: 3;

}

虽然乍一看实现了,但是放大后发现并不完美

bV2oBj?w=414&h=154

于是缩小白色三角形,但是放大后观察仍然有缺陷

.first-step:before {

width: 0;

height: 0;

content: '';

border-left: 14px solid white;

border-top: 11.5px solid transparent;

border-bottom: 11.5px solid transparent;

position: absolute;

right: -13px;

top: -2;

z-index: 3;

}

bV2oBZ?w=607&h=201

所以想问问怎么才能完美地实现这个带框箭头

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值