本文摘自PHP中文网,作者不言,侵删。
箭头符号我们是经常可以看到的,那么我们如何在不利用图像的情况下使用CSS制作箭头符号呢?本篇文章就来给大家介绍CSS制作箭头符号的方法。
话不多说,下面我们直接来看正文~
用CSS制作的箭头图标的方法
只需要使用CSS就可以创建箭头而不需要利用图像
首先,让我们来看看如何实现一个箭头,我将来制作一个从左上角到右下角的L形箭头。
一个直角转弯的箭头。
代码如下
HTML代码
1 2 3 4 5 6 7 8 9 10 11 12 | <!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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | .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代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | .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;
}
|
运行效果如下
阅读剩余部分
相关阅读 >>
css怎么定义div的宽度和高度
css怎么设置字体居中?
css文字如何隐藏
css outline-color属性怎么用
css如何不显示元素
css怎么让一段缩进
了解一些 提高前端开发效率的 css 属性选择器
html外部引用css文件不生效的原因
css怎么去掉div间距
css flex-basis属性怎么用
更多相关阅读请进入《css》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 如何使用CSS制作箭头符号