如何用css实现带箭头的边框

发布时间:2022-03-14 13:54:01 作者:iii
来源:亿速云 阅读:815

这篇文章主要介绍“如何用css实现带箭头的边框”,在日常操作中,相信很多人在如何用css实现带箭头的边框问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何用css实现带箭头的边框”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

  实现一个普通边框

  <style>

  .border {

  width: 100px;

  height: 50px;

  border: 1px solid red;

  }

  </style>

  <div class="border"></div>

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

  <style>

  .triangle {

  width: 0;

  height: 0;

  border: 100px solid red;

  border-right-color: green;

  border-left-color: blue;

  border-top-color: black;

  }

  </style>

  <div class="triangle"></div>

  三角形

  <style>

  .triangle-bottom {

  width: 0;

  height: 0;

  border: 100px solid transparent;

  border-top-color: red;

  }

  </style>

  <div class="triangle-bottom"></div>

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

  将三角形放入边框中

  <style>

  .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;

  }

  </style>

  <div class="border-triangle"></div>

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

  遮住多余三角形

  <style>

  .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;

  }

  </style>

  <div class="border-triangle-bottom"></div>

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

到此,关于“如何用css实现带箭头的边框”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. jQuery+CSS实现的UL表格,带边框提示
  2. css怎么实现箭头和带缺口提示框

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css

上一篇:CSS层叠上下文实例分析

下一篇:spark中如何读取impala的parquet并对String串的处理

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》