ES6标准新增了一种新的函数:Arrow Function(箭头函数),使用箭头(=>)定义函数。
其特点是:1、如果形参只有一个,则小括号可以省略;2、函数体如果只有一条语句,则花括号可以省略,函数的返回值为该条语句的执行结果;3、箭头函数this指向声明时所在作用域下this的值;4、箭头函数不能作为构造函数实例化;5、不能使用arguments。
心箭头
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>实心箭头</title>
<style>
.con{
width: 300px;
height: 300px;
border: 1px solid #ccc;
margin: 50px auto;
background-color:#ccc;
}
.arrow-top{
border-bottom: 10px solid #fff;
border-right: 10px solid #fff;
border-left: 10px solid #fff;
border-top: 10px solid #ccc;
width: 0px;
height: 0px;
position: relative;
top:-40px;
left:100px;
}
.arrow-bottom{
border-bottom: 10px solid #fff;
border-right: 10px solid #fff;
border-left: 10px solid #fff;
border-top: 10px solid #ccc;
width: 0px;
height: 0px;
position: relative;
top:-40px;
left:100px;
}
</style>
</head>
<body>
<div class="con">
<div class="arrow-top"> </div>
</div>
</body>
</html>
非实心箭头
角形
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>三角形</title>
<style type="text/css">
body{
background-color: pink;
}
div{
width: 0px;
height: 0px;
border-top: 10px solid blue;
border-right: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid transparent;
/* 唰(忽略不计) */
/* border-width: 10px;
border-style: solid;
border-color: green orange blue pink; */
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
箭头
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#bigBox{
width: 0;
height: 0;
border-top: 200px solid black;
border-right: 200px solid transparent;
border-bottom: 200px solid transparent;
border-left: 200px solid transparent;
}
#smallBox{
width: 0;
height: 0;
border-top: 160px solid white;
border-right: 160px solid transparent;
border-bottom: 160px solid transparent;
border-left: 160px solid transparent;
position: absolute;
left: 40px;
top: 0;
}
</style>
</head>
<body>
<div id="bigBox"></div>
<div id="smallBox"></div>
</body>
</html>
三角形使用案例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
list-style: none;
line-height: 40px;
cursor: pointer;
}
ul{
width: 200px;
margin: 0 auto;
border: 1px solid #000;
}
h3{
text-indent: 1em;
background-color: dodgerblue;
position: relative;
}
h3:before{
content: "";
width: 0;
height: 0;
border-top: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 8px solid transparent;
border-left: 8px solid #000;
position: absolute;
left: 5px;
top: 12px;
}
h3.active:before{
border-top: 8px solid #000;
border-left: 8px solid transparent;
left: 0px;
top: 15px;
}
</style>
</head>
<body>
<ul>
<li>
<h3>我的好友</h3>
</li>
<li>
<h3 class="active">企业好友</h3>
</li>
<li>
<h3>黑名单</h3>
</li>
</ul>
</body>
</html>
制作箭头
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#bigBox{
width: 0;
height: 0;
border-top: 200px solid black;
border-right: 200px solid transparent;
border-bottom: 200px solid transparent;
border-left: 200px solid transparent;
}
#smallBox{
width: 0;
height: 0;
border-top: 160px solid white;
border-right: 160px solid transparent;
border-bottom: 160px solid transparent;
border-left: 160px solid transparent;
position: absolute;
left: 40px;
top: 0;
}
</style>
</head>
<body>
<div id="bigBox"></div>
<div id="smallBox"></div>
</body>
</html>
实例: 实心箭头上下左右
*请认真填写需求信息,我们会在24小时内与您取得联系。