1.border属性transparent
默认值。边框颜色为透明。可以借此属性画一些基本形状,典型就是三角形
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
padding: 0;
margin: 0;
}
.css-cell {
position: relative;
width: 100%;
height: 300px;
}
.bubbly {
width: 0;
height: 0;
border-top: 40px solid transparent;
border-left: 40px solid #ff0000;
border-bottom: 40px solid transparent;
}
</style>
</head>
<body>
<div class="css-cell">
<div class="bubbly"></div>
</div>
</body>
</html>
所以,如果我们要做倒立三角形、向右的、或者向左的三角形,只需要为三角形底部设置边框,两腰边框透明即可
2.和伪类结合
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
padding: 0;
margin: 0;
}
.css-cell {
position: relative;
width: 100%;
height: 300px;
}
.bubbly {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #00ccbb;
border-radius: 8px;
width: 200px;
padding: 40px 10px;
text-align: center;
color: white;
font-size: 20px;
}
.bubbly:after {
content: '';
position: absolute;
bottom: -34px;
left: 50%;
border: 34px solid transparent;
border-top-color: #00ccbb;
border-bottom: 0;
border-left: 0;
}
</style>
</head>
<body>
<div class="css-cell">
<div class="bubbly"></div>
</div>
</body>
</html>