<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 0;
height: 0;
border:50px solid transparent;
border-right: 50px solid red;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
核心代码是border: 50px solid transparent; border-right: 50px solid red;此时三角形朝向是左;
可以设置border-left,border-top,border-bottom,来控制三角形的朝向;
开发中可以给一个盒子的before或者after伪元素设置三角,形成一种对话信息的形状。搭配绝对定位使用。
伪元素是行内元素,需要转换
.tip::before {
position: absolute;
top: 11px;
left: -12px;
display: inline-block;
content: '';
width: 0px;
height: 0px;
border: 6px solid transparent;
border-right: 6px solid #ccc;
}