css利用border画三角形原理

2024-09-23  本文已影响0人  CoderZb

注意:边框宽度为50,指的是水平和垂直方向的宽度

image.png
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>测试</title>
</head>
<body>
    <div class="triangle"></div>
</body>
</html>
<style>
.triangle {
    width: 100px;
    height: 100px;
    border: 50px solid;
    border-color: pink yellow red blue;
}
</style>

注意:边框宽度为50,指的是水平和垂直方向的宽度。所以这里50,指的是中心点距离正上、正右、正下、正左的距离为50

image.png
.triangle {
    width: 0px;
    height: 0px;
    border: 50px solid;
    border-color: pink yellow red blue;
}
.triangle {
    width: 0px;
    height: 0px;
    border-top: 50px solid pink;
    border-right: 50px solid yellow;
    border-bottom: 50px solid red;
    border-left: 0px solid blue;
}
.triangle {
    width: 0px;
    height: 0px;
    border-top: 50px solid pink;
    border-right: 50px solid yellow;
    border-bottom: 0px solid red;
    border-left: 50px solid blue;
}
.triangle {
    width: 0px;
    height: 0px;
    border-top: 50px solid pink;
    border-right: 0px solid yellow;
    border-bottom: 50px solid red;
    border-left: 50px solid blue;
}
.triangle {
    width: 0px;
    height: 0px;
    border-top: 0px solid pink;
    border-right: 50px solid yellow;
    border-bottom: 50px solid red;
    border-left: 50px solid blue;
}

总结:

.triangle {
    width: 0px;
    height: 0px;
    border-top: 0px solid pink;
    border-right: 50px solid transparent;
    border-bottom: 50px solid red;
    border-left: 50px solid transparent;
}
.triangle {
    width: 0px;
    height: 0px;
    border-top: 50px solid pink;
    border-right: 50px solid transparent;
    border-bottom: 0px solid red;
    border-left: 50px solid transparent;
}
.triangle {
    width: 0px;
    height: 0px;
    border-top: 50px solid transparent;
    border-right: 50px solid yellow;
    border-bottom: 50px solid transparent;
    border-left: 0px solid blue;
}
.triangle {
    width: 0px;
    height: 0px;
    border-top: 50px solid transparent;
    border-right: 0px solid yellow;
    border-bottom: 50px solid transparent;
    border-left: 50px solid blue;
}
上一篇下一篇

猜你喜欢

热点阅读