介绍
通过 html
+ css
, 实现不同方向的三角形
效果图
需求背景
现在经常会发现很多网页上的导航, 分类页等页面, 都会使用一个三角符号去指向内容,效果简洁美观 ; 并且现在很多的前端面试中, 也会问到怎么在网页当中实现一个三角的符号,所以自己做了, 各个方向的三角符号, 记得收藏哦~
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小三角</title>
<style>
.index {
height: 200px;
width: 500px;
margin: 50px auto;
background-color: #ddd;
}
.up{
width:0px;
height:0px;
border-bottom:30px solid #fff;
border-left:15px solid transparent;
border-right:15px solid transparent;
margin:10px auto;
}
.down{
width:0px;
height:0px;
border-top:30px solid #fff;
border-left:15px solid transparent;
border-right:15px solid transparent;
margin:10px auto;
}
.left{
width:0px;
height:0px;
border-right:30px solid #fff;
border-top:15px solid transparent;
border-bottom:15px solid transparent;
margin:10px auto;
}
.right{
width:0px;
height:0px;
border-left:30px solid #fff;
border-top:15px solid transparent;
border-bottom:15px solid transparent;
margin:10px auto;
}
</style>
</head>
<body>
<div class="index">
<!-- 正三角 -->
<div class="up"></div>
<!-- 倒三角 -->
<div class="down"></div>
<!-- 左边三角 -->
<div class="left"></div>
<!-- 右边三角 -->
<div class="right"></div>
</div>
</body>
</html>