html边框有箭头,css简单实现带箭头的边框

css简单实现带箭头的边框

普通边框

.border {

width: 100px;

height: 50px;

border: 1px solid red;

}

bVbhBts?w=260&h=136

实现由四个三角形组成的正方形

.triangle {

width: 0;

height: 0;

border: 100px solid red;

border-right-color: green;

border-left-color: blue;

border-top-color: black;

}

bVbhBtB?w=414&h=430

向下三角形

.triangle-bottom {

width: 0;

height: 0;

border: 100px solid transparent;

border-top-color: red;

}

将左右下边颜色设置为透明 transparent,得到向下的箭头

bVbhBtK?w=426&h=236

将三角形放入边框中

.border-triangle {

width: 100px;

height: 50px;

border: 1px solid red;

position: relative;

}

.border-triangle:before {

content: "";

position: absolute;

width: 0;

height: 0;

border: 4px solid transparent;

border-top-color: red;

left: 50%;

margin-left: -4px;

bottom: -8px;

}

将三角形设置为绝对定位,利用margin-left和left 定位到元素中间,bottom设置-8px,靠近边框底部居中

bVbhBtS?w=244&h=156

带箭头的边框

.border-triangle-bottom {

width: 100px;

height: 30px;

border: 1px solid #1d9cd6;

position: relative;

border-radius: 4px;

}

.border-triangle-bottom:after,

.border-triangle-bottom:before {

content: "";

position: absolute;

width: 0;

height: 0;

border: 4px solid transparent;

border-top-color: #1d9cd6;

left: 50%;

margin-left: -4px;

bottom: -8px;

}

.border-triangle-bottom:after {

border-top-color: #fff;

bottom: -7px;

}

将边框颜色换成好看的蓝色,将before和after伪元素都设置为绝对定位,定位到边框底部剧中,将after伪元素设置成白色,底部偏移量大于before 1px,遮住三角形底部的颜色。这样一个好看的箭头边框就实现了

bVbhBuQ?w=250&h=118

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值