每一个边框本质都是一个三角形,所以要设置一个三角形,边框3个边框设置成透明色,只让一个边框显示出颜色,就会显示三角形
<!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>
/* 每一个边框本质都是一个三角形,所以要设置一个三角形,边框3个边框设置成透明色,只让一个边框显示出颜色,就会显示三角形 */
.box1 {
width: 0;
height: 0;
border-top: 10px solid pink;
border-right: 10px solid red;
border-bottom: 10px solid blue;
border-left: 10px solid pink;
}
.box2 {
width: 0;
height: 0;
border: 50px solid transparent;
border-top-color: pink;
margin: 100px auto;
}
.jd {
position: relative;
width: 120px;
height: 249px;
background-color: pink;
}
.jd span {
position: absolute;
right: 15px;
top: -30px;
/* 相对于父元素向上移动2倍边框大小 */
width: 0;
height: 0;
line-height: 0;
font-size: 0;
border: 15px solid transparent;
border-bottom-color: red;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="jd">
<span></span>
</div>
</body>
</html>
结果: