利用border属性画一个三角形
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.box{
width: 100px;
height: 50px;
background: blue;
color: white;
}
.box1{
width: 0;
height: 0;
border: 10px solid rgb(0,0,0,0); /* 将所有边框都透明显示 */
border-top: 10px solid red; /* 只显示上面的边框 */
display: inline-block;
position: relative;
top: 7px;
}
</style>
</head>
<body>
<div class="box">导航<span class="box1"></span></div>
</body>
</html>
利用clip-path属性画一个三角形
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box1{
width: 200px;
height: 200px;
background-color: red;
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
</style>
</head>
<body>
<div class="box1"></div>
</body>
</html>
怎么样这种方法是不是很方便呢,clip-path属性可不仅仅是画一个简单的三角形,可以画的图形可比你想的还要多呢
clip-path绘制简单图形
这里作者就提供一下网站http://tools.jb51.net/code/css3path