登录  /  注册
首页 > web前端 > css教程 > 正文
如何使用CSS制作箭头符号
不言
发布: 2018-12-08 10:45:51
原创
6325人浏览过

箭头符号我们是经常可以看到的,那么我们如何在不利用图像的情况下使用CSS制作箭头符号呢?本篇文章就来给大家介绍CSS制作箭头符号的方法。

箭头

话不多说,下面我们直接来看正文~

用CSS制作的箭头图标的方法

只需要使用CSS就可以创建箭头而不需要利用图像

首先,让我们来看看如何实现一个箭头,我将来制作一个从左上角到右下角的L形箭头。

一个直角转弯的箭头。

代码如下

HTML代码

<!DOCTYPE html>
<html>
  <head>
  <meta charset="utf-8">
    <title>CSS arrow</title>
    <link rel="stylesheet" type="text/css" href="sample.css">
   <meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
  </head>
  <body>
   <div class="arrow"></div>
  </body>
</html>
登录后复制

CSS代码

sample.css

.arrow{
  position: relative;
  width: 200px;
  height: 50px;
  border-top: 8px solid #5bc0de;
  border-right: 8px solid #5bc0de;
  box-sizing: border-box;
}
.arrow::after{
  content: "";
  position: absolute;
  bottom: -14px;
  right: -17px;
  border-top: 14px solid #5bc0de;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
}
登录后复制

运行结果

在浏览器上显示如下效果

箭头

接下来介绍的几种箭头符号的制作HTML代码与上述相同,我们主要通过更改CSS代码来实现

三角形的箭头

CSS代码

.arrow{
  position: relative;
  display: inline-block;
  padding: 0 0 0 16px;
  color: #000;
  vertical-align: middle;
  text-decoration: none;
  font-size: 15px;
}

.arrow::before{
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  content: "";
  vertical-align: middle;
  box-sizing: border-box;
  width: 12px;
  height: 12px;
  border: 1px solid #ff0000;
  -webkit-border-radius: 25%;
  border-radius: 25%;
}

.arrow::after{
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  content: "";
  vertical-align: middle;
  left: 5px;
  box-sizing: border-box;
  width: 3px;
  height: 3px;
  border: 3px solid transparent;
  border-left: 3px solid #ff0000;
}
登录后复制

运行效果如下

将显示一个带有红色三角形的图标

2345截图20181208102042.png

“大于号”的箭头

CSS代码

.arrow{
  position: relative;
  display: inline-block;
  padding-left: 20px;
}

.arrow::before{
  content: '';
  width: 6px;
  height: 6px;
  border: 0px;
  border-top: solid 2px #5bc0de;
  border-right: solid 2px #5bc0de;
  -ms-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
  position: absolute;
  top: 50%;
  left: 0;
  margin-top: -4px;
}
登录后复制

运行结果

在浏览器上运行效果如下

2345截图20181208103201.png

在网页上这个箭头符号是经常可以用到的

制作向上的箭头

CSS代码

.arrow{
  width: 0px;
  border-color: #d9534f;
  border-style: solid;
  border-width: 30px;
  border-left-color: transparent;
  border-top-color: transparent;
  border-right-color: transparent;
}
登录后复制

运行效果

在浏览器上显示如下效果

箭头

最后我们来看一下传统向右的箭头符号

CSS代码

.arrow {
  display:inline-block;
  height:40px;
  width:80px;
  background-color:#5bc0de;
  position:relative;
  top:40px;
}

.arrow:before {
  position:absolute;
  content:"";
  width:0;
  height:0;
  border:60px solid transparent;
  border-left:60px solid #5bc0de;
  left:80px;
  top:-37px;
}
登录后复制

运行结果

在浏览器上将显示如下所示的效果

2345截图20181208104008.png

本篇文章到这里就全部结束了,更多相关的精彩内容大家可以移步到php中文网的CSS视频教程栏目进一步的学习!!!

以上就是如何使用CSS制作箭头符号的详细内容,更多请关注php中文网其它相关文章!

相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学