自定义三角形_带三角形的边框

1 篇文章 0 订阅
这段代码展示了如何使用CSS伪元素`:before`和`:after`创建带有三角形边框的自定义形状。通过调整边框宽度和透明度,可以在左、右侧生成指向外部或内部的三角形。此技术常用于消息提示或者箭头指示等设计中,且适用于前端开发中的定位和布局。
摘要由CSDN通过智能技术生成

自定义三角形_带三角形的边框

代码:
注意:父盒子需要定位 position: relative

.leftMsg::before {
  box-sizing: content-box;
  width: 0px;
  height: 0px;
  position: absolute;
  left: -16px;
  top: 14px;
  padding: 0;
  border-right: 8px solid #ffffff;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 8px solid transparent;
  display: block;
  content: "";
  z-index: 12;
}
.leftMsg::after {
  box-sizing: content-box;
  width: 0px;
  height: 0px;
  position: absolute;
  left: -18px;
  top: 13px;
  padding: 0;
  border-right: 9px solid #3cacb6;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 9px solid transparent;
  display: block;
  content: "";
  z-index: 10;
}
.rightMsg::before {
  box-sizing: content-box;
  width: 0px;
  height: 0px;
  position: absolute;
  right: -16px;
  top: 14px;
  padding: 0;
  border-right: 8px solid transparent;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 8px solid#ffffff;
  display: block;
  content: "";
  z-index: 12;
}
.rightMsg::after {
  box-sizing: content-box;
  width: 0px;
  height: 0px;
  position: absolute;
  right: -18px;
  top: 13px;
  padding: 0;
  border-right: 9px solid transparent;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 9px solid #3cacb6;
  display: block;
  content: "";
  z-index: 10;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值