弹性布局flex!!之精美聊天框案例(舔狗日记)!!

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

霸道总裁之得不到则毁掉!

该案例大量使用flex布局,提高自己flex布局的熟练度,本人运用VScode进行开发。
你做完次案例将学到

  1. 运用CSS绘画三角形。
  2. flex布局:
    justify-content,align-items,order,flex。
  3. 做一个舔狗~。

在这里插入图片描述

  1. 建立一个html文件

  2. 编写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>
  1. 编写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;
}

在这里插入图片描述

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值