前端学习
前段学习之三角制作
图片展示:
一、三角制作
1.指定一个没有大小的盒子(要求宽和高必须为0,只设置边框长度)
<style>
.box1 {
width: 0;
height: 0;
border: 10px solid pink;
}
</style>
<body>
<div class="box1"></div>
</body>
2.若把四个边框改成不同的颜色
<style>
.box1 {
width: 0;
height: 0;
border-top: 10px solid pink;
border-right: 10px solid red;
border-bottom: 10px solid blue;
border-left: 10px solid green;
}
</style>
<body>
<div class="box1"></div>
</body>
则如下图所示:
3.若把四个三角形的其中三个设置为透明色,则得到一个三角形
top
<style>
.box1 {
width: 0;
height: 0;
border: 10px solid transparent;
border-top-color: pink;
}
</style>
<body>
<div class="box1"></div>
</body>
则如下图所示:
right
<style>
.box1 {
width: 0;
height: 0;
border: 10px solid transparent;
border-right-color: red;
}
</style>
<body>
<div class="box1"></div>
</body>
则如下图所示:
bottom
<style>
.box1 {
width: 0;
height: 0;
border: 10px solid transparent;
border-bottom-color: blue;
}
</style>
<body>
<div class="box1"></div>
</body>
则如下图所示:
left
<style>
.box1 {
width: 0;
height: 0;
border: 10px solid transparent;
border-left-color: green;
}
</style>
<body>
<div class="box1"></div>
</body>
则如下图所示:
若想放大缩小三角,则调节边框大小即可:
eg:
border: 10px solid transparent;
border: 50px solid transparent;
border: 100px solid transparent;
二、三角制作之直角三角形
eg:京东三角制作案例
原理
如上述 2所示
若把下边框长度设为0:
<style>
.box1 {
width: 0;
height: 0;
border-top: 10px solid pink;
border-right: 10px solid red;
border-bottom: 10px solid blue;
border-left: 10px solid green;
}
</style>
<body>
<div class="box1"></div>
</body>
则如下图所示:(为等腰三角形)
若想得到直角三角形,则把top边框值设大:
<style>
.box1 {
width: 0;
height: 0;
border-top: 100px solid pink;
border-right: 10px solid red;
border-bottom: 0px solid blue;
border-left: 10px solid green;
}
</style>
<body>
<div class="box1"></div>
</body>
则如下图所示:(为直角三角形)
把左边框设为0(上边框不能为0):
<style>
.box1 {
width: 0;
height: 0;
border-top: 100px solid pink;
border-right: 10px solid red;
border-bottom: 0px solid blue;
border-left: 0px solid green;
}
</style>
<body>
<div class="box1"></div>
</body>
则如下图所示:
做直角三角形:
- 左边和下边的边框宽度设置为0;
- 把上边框宽度调大
- 把上边框颜色设为透明色
<style>
.box1 {
width: 0;
height: 0;
border-top: 100px solid transparent;
border-right: 50px solid red;
border-bottom: 0px solid blue;
border-left: 0px solid green;
}
</style>
<body>
<div class="box1"></div>
</body>
简写代码:
width: 0;
height: 0;
border-color:transparent red transparent transparent;
border-style:solid;
border-width: 100px 50px 0 0;
如图所得为直角三角形:
(此为借鉴pink老师前段入门视频所做的笔记,仅供参考。)