主要用到了 border 的 transparent 属性 , 如有不懂 可以参考 https://www.cnblogs.com/youhong/p/6530575.html 写的很详细
代码如下:
<!DOCTYPE html>
<html>
<head>
<title>三角形</title>
</head>
<body>
<center>
<div class="demo"></div>
</center>
<style type="text/css">
.demo{
width:100px;
height: 100px;
background:#333;
position: relative;
}
.demo:hover{
background:red;
}
.demo:hover.demo:after{
content:"";
position: absolute;
top:100%;
left: 45px;
height: 0;
width: 0;
border:solid transparent;
border-width:10px;
border-top-color:red;
}
</style>
</body>
</html>