纯html+css实现向上向下向左向右,空心实心箭头。

 前端开发中会使用到各种各样的箭头,有时候不断替换图片实在麻烦,掌握这些css小技巧,轻松实现各种箭头。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>实心箭头上下左右都有哦</title>
</head>
<body>
<style type="text/css">

/* 向上的箭头 */

.arrow-top {
  width: 0;   
  height: 0;   
  border-left: 10px solid transparent; 
  border-right: 10px solid transparent;
  border-bottom: 10px solid #217AFF; 
  font-size: 0;  
  line-height: 0; 
}
/* 向右的箭头 */

.arrow-right {
  width: 0;   
  height: 0;   
  border-left: 10px solid #217AFF;
  border-right: 10px solid transparent;
  border-bottom: 10px solid transparent;
  font-size: 0;  
  line-height: 0;
}
/* 向下的箭头 */

.arrow-bottom {
  width: 0;   
  height: 0;   
  border-left: 4px solid transparent;  /* 左边框的宽 */  
  border-right: 4px solid transparent; /* 右边框的宽 */  
  border-top: 7px solid #217AFF; /* 下边框的长度|高,以及背景色 */  
  font-size: 0;  
  line-height: 0; 
}
/* 向左的箭头 */

.arrow-left {
  width: 0;   
  height: 0;   
  border-left: 10px solid transparent;
  border-right: 10px solid #217AFF;
  border-bottom: 10px solid transparent;
  font-size: 0;  
  line-height: 0;
}
</style>
</head>
<body>
<div class="arrow">
<span class="arrow-top"></span>
<span class="arrow-right"></span>
<span class="arrow-bottom"></span>
<span class="arrow-left"></span>
</div>
</body>
</html>

 

/* 空心箭头 */
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css制作空心的上下左右的箭头</title>
<style type="text/css">
.box {
width: 100px;
height: 500px;
margin: 0 auto;
background: white;
}

.arrow-box {
width: 30px;
height: 30px;
margin: 20px auto;
position: relative;
}
/*右箭头*/

.right {
width: 20px;
height: 20px;
position: absolute;
left: 0;
top: 0;
}

.right-arrow1,
.right-arrow2 {
width: 0;
height: 0;
display: block;
position: absolute;
left: 0;
top: 0;
border-top: 10px transparent dashed;
border-right: 10px transparent dashed;
border-bottom: 10px transparent dashed;
border-left: 10px white solid;
overflow: hidden;
}

.right-arrow1 {
left: 1px;
/*重要*/
border-left: 10px red solid;
}

.right-arrow2 {
border-left: 10px white solid;
}
/*左箭头*/

.left {
width: 20px;
height: 20px;
position: absolute;
left: 0;
top: 0;
z-index: 2;
/*兼容ie8-*/
}

.left-arrow1,
.left-arrow2 {
width: 0;
height: 0;
display: block;
position: absolute;
left: 0;
top: 0;
z-index: 5;
/*兼容ie8-*/
border-top: 10px transparent dashed;
border-left: 10px transparent dashed;
border-bottom: 10px transparent dashed;
border-right: 10px white solid;
overflow: hidden;
}

.left-arrow1 {
border-right: 10px red solid;
}

.left-arrow2 {
left: 1px;
/*重要*/
border-right: 10px white solid;
}
/*上箭头*/

.top {
width: 20px;
height: 20px;
position: absolute;
left: 0;
top: 0;
z-index: 2;
/*兼容ie8-*/
}

.top-arrow1,
.top-arrow2 {
width: 0;
height: 0;
display: block;
position: absolute;
left: 0;
top: 0;
z-index: 5;
/*兼容ie8-*/
border-top: 10px transparent dashed;
border-left: 10px transparent dashed;
border-right: 10px transparent dashed;
border-bottom: 10px white solid;
overflow: hidden;
}

.top-arrow1 {
border-bottom: 10px red solid;
}

.top-arrow2 {
top: 1px;
/*重要*/
border-bottom: 10px white solid;
}
/*下箭头*/

.bottom {
width: 20px;
height: 20px;
position: absolute;
left: 0;
top: 0;
z-index: 2;
/*兼容ie8-*/
}

.bottom-arrow1,
.bottom-arrow2 {
width: 0;
height: 0;
display: block;
position: absolute;
left: 0;
top: 0;
z-index: 5;
/*兼容ie8-*/
border-bottom: 10px transparent dashed;
border-left: 10px transparent dashed;
border-right: 10px transparent dashed;
border-top: 10px white solid;
overflow: hidden;
}

.bottom-arrow1 {
top: 1px;
/*重要*/
border-top: 10px red solid;
}

.bottom-arrow2 {
border-top: 10px white solid;
}
</style>

<body>
<div class="box">
<p> 右箭头</p>
<div class="arrow-right arrow-box">
<b class="right"><i class="right-arrow1"></i><i class="right-arrow2"></i></b>
</div>
<p> 左箭头</p>
<div class="arrow-left arrow-box">
<b class="left"><i class="left-arrow1"></i><i class="left-arrow2"></i></b>
</div>
<p> 上箭头</p>
<div class="arrow-top arrow-box">
<b class="top"><i class="top-arrow1"></i><i class="top-arrow2"></i></b>
</div>
<p> 下箭头</p>
<div class="arrow-bottom arrow-box">
<b class="bottom"><i class="bottom-arrow1"></i><i class="bottom-arrow2"></i></b>
</div>
</div>
</body>
</html>

 

 

/* 实心垂直三角形 */

<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
.vertical_left_top {
display: inline-block;
position: absolute;
left: 0px;
top: 0px;
}

.vertical_left_top::before {
border: 25px solid;
border-color: red transparent transparent red;
display: inline-block;
content: '';
}

.vertical_right_bottom {
display: inline-block;
position: absolute;
left: 0px;
top: 70px;
}

.vertical_right_bottom::before {
border: 25px solid;
border-color: transparent red red transparent;
display: inline-block;
content: '';
}

.vertical_right_top {
display: inline-block;
position: absolute;
left: 0px;
top: 140px;
}

.vertical_right_top::before {
border: 25px solid;
border-color: red red transparent transparent;
display: inline-block;
content: '';
}

.vertical_left_bottom {
display: inline-block;
position: absolute;
left: 0px;
top: 210px;
}

.vertical_left_bottom::before {
border: 25px solid;
border-color: transparent transparent red red;
display: inline-block;
content: '';
}
</style>

<body>
<div class="vertical_left_top"></div>
<br />
<div class="vertical_right_bottom"></div>
<br />
<div class="vertical_right_top"></div>
<br />
<div class="vertical_left_bottom"></div>
</body>

</html>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值