网页中一些常用的三角形都是直接画出来的。(等边三角形与直角三角形)
例:一个上三角形
height: 0;width: 0;
border: 50px solid transparent; border-bottom-color: pink;
- 利用边框的做法,将其它边框的颜色设为透明颜色(transparent)
下面代码可直接运行使用
(里面有直角三角形和等边三角形还有一个直角三角形的用例)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>三角形</title>
<style>
/*清除浮动*/
.clearfix:before,
.clearfix:after {
content: "";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
/*清除浮动*/
.box01 {
height: 101px;
}
.box001,
.box002,
.box003,
.box004,
.box005,
.box006 {
float: left;
margin-left: 50px;
height: 0;
width: 0;
/*兼容性*/
line-height: 0;
font-size: 0;
cursor: not-allowed;
/*鼠标样式*/
border-color: pink blue green red;
/*每个方向的颜色*/
border-style: solid;
/*样式*/
}
.box001 {
/* border-top: 50px solid pink;
border-right: 50px solid blue;
border-bottom: 50px solid green;
border-left: 50px solid red; */
border-width: 50px;
}
.box002 {
border-width: 50px 50px 0 50px;
}
.box003 {
border-width: 100px 50px 0 50px;
}
.box004 {
border-width: 100px 50px 0 0px;
}
.box005 {
border-top-color: transparent;
/*颜色设置为透明*/
border-width: 100px 50px 0 0px;
}
.box006 {
border-right-color: transparent;
border-width: 100px 50px 0 0px;
}
.boxtop,
.boxright,
.boxbottom,
.boxleft {
float: left;
margin-top: 50px;
height: 0;
width: 0;
/*兼容性*/
line-height: 0;
font-size: 0;
cursor: not-allowed;
margin-left: 50px;
border: 50px solid transparent;
}
.boxtop {
border-top-color: pink;
}
.boxright {
border-right-color: blue;
}
.boxbottom {
border-bottom-color: green;
}
.boxleft {
border-left-color: red;
}
.box02 {
position: relative;
margin: 100px 0 0 50px;
width: 400px;
height: 200px;
background-color: pink;
cursor: not-allowed;
}
.box02 span {
position: absolute;
}
.box02 span:nth-child(1) {
top: 150px;
/* border-top-color: black; */
}
.box02 span:nth-child(2) {
left: -150px;
}
.box02 span:nth-child(3) {
top: -150px;
left: 250px;
}
.box02 span:nth-child(4) {
left: 350px;
}
.box03 {
margin-top: 100px;
}
.box03 .price {
width: 160px;
height: 24px;
border: 1px solid red;
line-height: 24px;
/* margin: 0 auto; */
}
.box03 .price span:nth-child(1){
position: relative;
float: left;
margin-right: 8px;
width: 90px;
height: 100%;
text-align: center;
color: #fff;
font-weight: 700;
background-color: red;
}
.box03 .price span:nth-child(1) i{
position: absolute;
right: 0;
top: 0;
width: 0;
height: 0;
border-top-color: red;
border-style: solid;
border-width: 24px 12px 0 0;
}
.box03 .price span:nth-child(2){
font-size: 12px;
color: grey;
text-decoration: line-through;
}
</style>
</head>
<body>
<div class="box01">
<div class="box001"></div>
<div class="box002"></div>
<div class="box003"></div>
<div class="box004"></div>
<div class="box005"></div>
<div class="box006"></div>
</div>
<div class="box clearfix">
<div class="boxtop"></div>
<div class="boxright"></div>
<div class="boxbottom"></div>
<div class="boxleft"></div>
</div>
<div class="box02">
<span class="boxtop"></span>
<span class="boxright"></span>
<span class="boxbottom"></span>
<span class="boxleft"></span>
</div>
<div class="box03">
<div class="price">
<span>¥1234<i></i></span>
<span>¥8848</span>
</div>
</div>
</body>
</html>