霸道总裁之得不到则毁掉!
该案例大量使用flex布局,提高自己flex布局的熟练度,本人运用VScode进行开发。
你做完次案例将学到
- 运用CSS绘画三角形。
- flex布局:
justify-content,align-items,order,flex。- 做一个舔狗~。

-
建立一个html文件
-
编写HTML代码
<!-- 大盒子 -->
<!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="main">
<!-- 头部 start -->
<div class="header">
<div class="back"></div>
<div class="text">宝!</div>
<div class="time">i</div>
</div>
<!-- 头部 end -->
<!-- 聊天框 start -->
<div class="word">
<!-- ta -->
<div class="Tchat1">
<div class="head"></div>
<div class="text">宝?我今天去输液的,输的什么液,想你的夜~</div>
</div>
<!-- wo -->
<div class="Wchat1">
<div class="head"></div>
<div class="text">dog!</div>
</div>
<!-- ta -->
<div class="Tchat1">
<div class="head"></div>
<div class="text">我养你啊 笨!</div>
</div>
<!-- wo -->
<div class="Wchat1">
<div class="head"></div>
<div class="text">dog!</div>
</div>
<!-- ta -->
<div class="Tchat1">
<div class="head"></div>
<div class="text">你对一个喜欢你 关心你 担心你的人就这么爱答不理的。</div>
</div>
<!-- wo -->
<div class="Wchat1">
<div class="head"></div>
<div class="text">dog!</div>
</div>
</div>
<!-- 聊天框 end -->
<!-- 键盘 start -->
<div class="key">
<div class="one">
<li>Q</li>
<li>W</li>
<li>E</li>
<li>R</li>
<li>T</li>
<li>Y</li>
<li>U</li>
<li>I</li>
<li>O</li>
<li>P</li>
</div>
<div class="two">
<li>A</li>
<li>S</li>
<li>D</li>
<li>F</li>
<li>G</li>
<li>H</li>
<li>J</li>
<li>K</li>
<li>L</li>
</div>
<div class="three">
<li></li>
<li>S</li>
<li>D</li>
<li>F</li>
<li>G</li>
<li>H</li>
<li>J</li>
<li>K</li>
<li></li>
</div>
<div class="show">
王 思 聪 d o g !
</div>
</div>
<!-- 键盘 end -->
</div>
</body>
</html>
- 编写CSS代码
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?p4ssmb');
src: url('fonts/icomoon.eot?p4ssmb#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?p4ssmb') format('truetype'),
url('fonts/icomoon.woff?p4ssmb') format('woff'),
url('fonts/icomoon.svg?p4ssmb#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.main {
width: 360px;
height: 600px;
background-color: #303056;
}
.main .header {
display: flex;
justify-content: space-around;
align-items: center;
width: 100%;
height: 50px;
background: #3D4166;
}
.main .header .back {
position: relative;
width: 8px;
height: 8px;
border-left: 2px solid #606489;
border-bottom: 2px solid #606489;
transform: rotate(50deg);
}
.text {
color: #606489;
font-size: 12px;
}
.time {
width: 18px;
height: 18px;
border-radius: 50%;
border: 1px solid #606489;
text-align: center;
line-height: 18px;
font-size: 12px;
color: #606489;
}
.word {
width: 100%;
height: 400px;
/* margin-top: 40px; */
}
.word .Tchat1 {
display: flex;
padding: 0 10px;
align-items: center;
width: 100%;
height: 40px;
margin-top: 20px;
background: #303056;
}
.word .Tchat1 .head {
flex: 1;
height: 28px;
border: 2px solid #606060;
border-radius: 50%;
background: url(./zx.jpg) no-repeat;
background-size: cover;
}
.word .Tchat1 .text {
position: relative;
margin-left: 10px;
flex: 13;
height: 28px;
background: #8386A7;
border-radius: 10px;
text-align: center;
line-height: 28px;
}
.word .Tchat1 .text::after {
content: '';
width: 0;
height: 0;
border: 5px solid transparent;
border-right: 5px solid #8386A7;
position: absolute;
left: -10px;
top: 50%;
transform: translateY(-50%);
}
.word .Wchat1 {
display: flex;
padding: 0 10px;
align-items: center;
width: 100%;
height: 40px;
margin-top: 20px;
background: #303056;
}
.word .Wchat1 .head {
flex: 1;
height: 28px;
border: 2px solid #606060;
order: 2;
border-radius: 50%;
background: url(./c.jpg) no-repeat;
background-size: cover;
}
.word .Wchat1 .text {
position: relative;
margin-right: 10px;
flex: 13;
order: 1;
height: 28px;
background: #8386A7;
border-radius: 10px;
text-align: center;
line-height: 28px;
}
.word .Wchat1 .text::before {
content: '';
width: 0;
height: 0;
border: 5px solid transparent;
border-left: 5px solid #8386A7;
position: absolute;
right: -10px;
top: 50%;
transform: translateY(-50%);
}
.key {
width: 100%;
height: 130px;
background: #3D4164;
}
li {
list-style: none;
}
.key .one,
.two,
.three {
display: flex;
width: 100%;
height: 35px;
}
.key .one li {
color: #fff;
font-size: 12px;
flex: 1;
text-align: center;
line-height: 40px;
height: 40px;
}
.key .two {
padding: 0 10px;
}
.key .two li {
font-size: 12px;
color: #fff;
flex: 1;
text-align: center;
line-height: 35px;
height: 35px;
}
.key .three li {
font-size: 12px;
color: #fff;
flex: 1;
text-align: center;
line-height: 35px;
height: 35px;
}
.key .three li:nth-child(1) {
font-family: 'icomoon';
color: #10DAC4;
}
.key .three li:last-child {
font-family: 'icomoon';
color: #10DAC4;
}
.key .show {
width: 100%;
height: 25px;
color: #fff;
font-size: 12px;
text-align: center;
line-height: 25px;
}
怎么使用CSS绘制三角?
使用到的属性有:border 。
HTML代码:
<div class="box"></div>
CSS代码:
.box {
width: 0px;
height: 0px;
border: 10px solid transparent;
border-left: 10px solid pink;
}

本文通过一个生动的舔狗日记案例,深入讲解如何利用CSS3的flex布局创建精美的聊天界面。读者将学习到如何绘制CSS三角形,掌握justify-content、align-items、order和flex等flex关键属性,以及如何在VScode中进行开发。
917





