利用html和css写三角形
Posted 芜独独
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用html和css写三角形相关的知识,希望对你有一定的参考价值。
第一步
代码
<!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>
</head>
<body>
<div class="trangle"></div>
</body>
</html>
<style>
*
margin: 0;
padding: 0;
.trangle
margin: 0 auto;
margin-top: 100px;
width: 0;
height: 0;
border: 200px solid #909399;
border-top-color: #409EFF;
border-bottom-color: #67C23A;
border-left-color: #E6A23C;
border-right-color: #F56C6C;
</style>
效果图
第二步
border-bottom: 0;
border-left-color: transparent;
border-right-color: transparent;
代码
<!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>
</head>
<body>
<div class="trangle"></div>
</body>
</html>
<style>
*
margin: 0;
padding: 0;
.trangle
margin: 0 auto;
margin-top: 100px;
width: 0;
height: 0;
border: 200px solid #909399;
border-top-color: #409EFF;
border-bottom-color: #67C23A;
border-left-color: #E6A23C;
border-right-color: #F56C6C;
/* 根据需要调整方位 */
border-bottom: 0;
border-left-color: transparent;
border-right-color: transparent;
</style>
效果图
简化一下代码
<!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>
</head>
<body>
<div class="trangle"></div>
</body>
</html>
<style>
*
margin: 0;
padding: 0;
.trangle
margin: 0 auto;
margin-top: 100px;
width: 0;
height: 0;
border-bottom: 200px solid #67C23A;
border-left: 200px solid transparent;
border-right: 200px solid transparent;
</style>
效果图
如果不要颜色的话
.trangle::after
content: "";
z-index: 99;
border-left: 197px solid transparent;
border-right: 197px solid transparent;
border-bottom: 197px solid white;
position: absolute;
top: 101px;
left: 103px;
<!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>
</head>
<body>
<div class="trangle"></div>
</body>
</html>
<style>
*
margin: 0;
padding: 0;
.trangle
margin-left: 100px;
margin-top: 100px;
width: 0;
height: 0;
border-bottom: 200px solid #67C23A;
border-left: 200px solid transparent;
border-right: 200px solid transparent;
/* 与后面有关的代码 */
z-index: 1;
.trangle::after
content: "";
z-index: 99;
border-left: 197px solid transparent;
border-right: 197px solid transparent;
border-bottom: 197px solid white;
position: absolute;
top: 101px;
left: 103px;
</style>
效果图
以上是关于利用html和css写三角形的主要内容,如果未能解决你的问题,请参考以下文章