为了网站的性能速度,我们都是秉承着少用图片的原生质,通过css实现三角形和带边框的三角形
因为图片实现有两个很明显的缺点:一是图片大小比较大数据传输量大,二是一张图片会引发一次http请求。这两个方面都会影响页面加载速度,并且增加服务器负担
三角形
把width、height设置为0
<!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>三角形</title>
<style type="text/css">
* {
padding: 0px;
margin:0px;
}
.box {
width: 0px;
height: 0px;
border-style: solid;
border-width: 20px;
border-color: transparent transparent black transparent;
}
</style>
</head>
<body>
<div class="box">
</div>
</body>
</html>
带边框的三角形
<!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>flex-grow讲解</title>
<style type="text/css">
* {
padding: 0px;
margin:0px;
}
.box {
width: 0px;
height: 0px;
border-style: solid;
border-width: 20px;
border-color: transparent transparent black transparent;
position: relative;
}
.inner {
width: 0;
height: 0;
border-style: solid;
border-width: 19px;
border-color: transparent transparent yellow transparent;
position: absolute;
top: -18px;
left: -19px;
}
</style>
</head>
<body>
<div class="box">
<div class="inner"></div>
</div>
</body>
</html>