[CSS3]Flex布局

[复制链接]
发表于 2025-5-25 16:37:19 | 显示全部楼层 |阅读模式
 

Flex布局

能够使用Flex布局模型灵活、快速的开辟网页

  • 是一种浏览器提倡的布局模型
  • 布局网页更简单、灵活
  • 避免浮动脱标的题目
  • 手机端放心用, pc端ie低版本不兼容
  • 技术兼容性查询网站: Can I use... Support tables for HTML5, CSS3, etc


Flex底子概念

  • 基于 Flex 精确灵活控制块级盒子的布局方式, 避免浮动布局中离开文档流现象发生
  • Flex布局非常适合布局化布局
  • 在父盒子(必须是亲爹)身上添加 display:flex; 就会开启flex布局
  • 构成部分


  • 弹性容器
  • 弹性盒子
  • 主轴
  • 侧轴/交叉轴



开启Flex布局
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>体验flex布局</title>
  8.     <style>
  9.         * {
  10.             margin: 0;
  11.             padding: 0;
  12.         }
  13.         .box {
  14.             /* 视觉效果: 子级在一行水平排列 */
  15.             /* 水平排列的原因: 默认主轴在水平方向, 弹性盒子都是沿着主轴排列 */
  16.             display: flex;
  17.             height: 200px;
  18.             border: 1px solid #000;
  19.         }
  20.         .box div {
  21.             width: 100px;
  22.             height: 100px;
  23.             background-color: pink;
  24.         }
  25.     </style>
  26. </head>
  27. <body>
  28.     <div class="box">
  29.         <div>1</div>
  30.         <div>2</div>
  31.         <div>3</div>
  32.     </div>
  33. </body>
  34. </html>v
复制代码


使用justify-content调治元素在主轴的对齐方式

  • 通过调解主轴的对其方式可以设置弹性盒子之间的间距

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>主轴对齐方式</title>
  8.     <style>
  9.         * {
  10.             margin: 0;
  11.             padding: 0;
  12.         }
  13.         .box {
  14.             display: flex;
  15.             /* 沿主轴居中排列 */
  16.             justify-content: center;
  17.             /* 空白在子集之间(两侧没有) */
  18.             justify-content: space-between;
  19.             /* 所有盒子的间距都相等 */
  20.             justify-content: space-evenly;
  21.             /* 间距加在子级的两侧 */
  22.             /* 视觉效果: 子集之间的空白是两侧空白的2倍 */
  23.             justify-content: space-around;
  24.             height: 200px;
  25.             margin: auto;
  26.             border: 1px solid #000;
  27.         }
  28.         .box div {
  29.             width: 100px;
  30.             height: 100px;
  31.             background-color: pink;
  32.         }
  33.     </style>
  34. </head>
  35. <body>
  36.     <div class="box">
  37.         <div>1</div>
  38.         <div>2</div>
  39.         <div>3</div>
  40.     </div>
  41. </body>
  42. </html>
复制代码






使用align-items调治元素在侧轴的对齐方式

  • 通过调解侧轴的对其方式设置弹性盒子之间的间距
  • 修改侧轴对齐方式的两种方法:


  • align-items (添加到弹性容器)(添加给父元素---控制全部儿子)
  • align-self (添加到弹性盒子 )(添加到儿子身上---控制某个子集)

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>侧轴对齐方式</title>
  8.     <style>
  9.         * {
  10.             margin: 0;
  11.             padding: 0;
  12.         }
  13.         .box {
  14.             display: flex;
  15.             /* 拉伸,默认值(子集不能设置高度, 否则不拉伸) */
  16.             /* 显示效果: 子集拉伸至撑满父盒子 */
  17.             align-items: stretch;
  18.             /* 居中 */
  19.             /* 由于子集没设置宽高, 就是内容的宽高 */
  20.             /* 没有拉伸效果, 是因覆盖了stretch默认值 */
  21.             align-items: center;
  22.             height: 300px;
  23.             margin: auto;
  24.             border: 1px solid #000;
  25.         }
  26.         .box div {
  27.             /*
  28.               flex布局下, 如果子集设置了宽高, 以设置的值为准
  29.               如果没有设置宽高, 默认会存在拉伸效果
  30.             */
  31.             /* width: 100px; */
  32.             /* height: 100px; */
  33.             background-color: pink;
  34.         }
  35.         /* 单独设置某个弹性盒子的侧轴对齐方式 */
  36.         .box div:nth-child(2) {
  37.             align-self: self-start;
  38.         }
  39.     </style>
  40. </head>
  41. <body>
  42.     <div class="box">
  43.         <div>1111</div>
  44.         <div>2</div>
  45.         <div>3</div>
  46.     </div>
  47. </body>
  48. </html>
复制代码





使用flex属性修改弹性盒子伸缩比

  • 通过修改弹性盒子的伸缩比控制子集的尺寸
  • flex: 值; (取值为整数, 体现占用父级剩余尺寸的比例)
  • 属性要添加给儿子
4. 代码示例
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Document</title>
  8.     <style>
  9.         * {
  10.             margin: 0;
  11.             padding: 0;
  12.         }
  13.         .box {
  14.             display: flex;
  15.             height: 300px;
  16.             border: 1px solid #000;
  17.         }
  18.         .box div {
  19.             height: 200px;
  20.             margin: 0 20px;
  21.             background-color: pink;
  22.         }
  23.         .box div:nth-child(1) {
  24.             width: 50px;
  25.         }
  26.         .box div:nth-child(2) {
  27.             /* 占用父级剩余尺寸的份数 */
  28.             flex: 2;
  29.         }
  30.         .box div:nth-child(3) {
  31.             flex: 1;
  32.         }
  33.     </style>
  34. </head>
  35. <body>
  36.     <div class="box">
  37.         <div>1</div>
  38.         <div>2</div>
  39.         <div>3</div>
  40.     </div>
  41. </body>
  42. </html>
复制代码



使用flex-direction改变元素分列方向

  • 思考: Flex布局模型中,弹性盒子默认沿着哪个方向分列?
  • 答: 水平方向, 由于主轴默认是水平方向,侧轴默认是垂直方向
  • 思考: 怎样实现内容垂直分列 ? 答: 修改主轴方向
  • 修改主轴方向属性: flex-direction


  • 示例代码
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>主轴方向</title>
  8.     <style>
  9.         * {
  10.             margin: 0;
  11.             padding: 0;
  12.         }
  13.         li {
  14.             list-style: none;
  15.         }
  16.         .box li {
  17.             display: flex;
  18.             /* 1. 先确定主轴方向; 2. 再选择对应的属性实现主轴或侧轴的对齐方式 */
  19.             /* 修改主轴方向: 列 */
  20.             flex-direction: column;
  21.             /* 视觉效果: 实现元素水平居中 */
  22.             align-items: center;
  23.             /* 视觉效果: 实现元素垂直居中 */
  24.             justify-content: center;
  25.             width: 80px;
  26.             height: 80px;
  27.             border: 1px solid #ccc;
  28.         }
  29.         .box img {
  30.             width: 32px;
  31.             height: 32px;
  32.         }
  33.     </style>
  34. </head>
  35. <body>
  36.     <div class="box">
  37.         <ul>
  38.             <li>
  39.                 <img src="./images/media.png" alt="">
  40.                 <span>媒体</span>
  41.             </li>
  42.         </ul>
  43.     </div>
  44. </body>
  45. </html>
复制代码


使用flex-wrap实现弹性盒子多行分列结果

  • 思考: 默认环境下,多个弹性盒子怎样显示 ?
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>弹性盒子换行</title>
  8.     <style>
  9.         * {
  10.             margin: 0;
  11.             padding: 0;
  12.         }
  13.         .box {
  14.             /* 了解flex布局下, 多行内容的默认展示效果 */
  15.             display: flex;
  16.             height: 500px;
  17.             border: 1px solid #000;
  18.         }
  19.         .box div {
  20.             /* flex布局模型下 */
  21.             /* 元素的尺寸没有超过父元素, 按设置的尺寸展示  */
  22.             /* 元素的尺寸超过父元素, 默认不会换行, 而是压缩子元素, 直到不超过父元素  */
  23.             /* 这就是弹性盒子的特点 */
  24.             width: 100px;
  25.             height: 100px;
  26.             background-color: pink;
  27.         }
  28.     </style>
  29. </head>
  30. <body>
  31.     <div class="box">
  32.         <div>1</div>
  33.         <div>2</div>
  34.         <div>3</div>
  35.         <div>4</div>
  36.         <div>5</div>
  37.         <div>6</div>
  38.         <div>7</div>
  39.         <div>8</div>
  40.     </div>
  41. </body>
  42. </html>
复制代码


  • 弹性盒子换行显示: flex-wrap:wrap;
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>弹性盒子换行</title>
  8.     <style>
  9.         * {
  10.             margin: 0;
  11.             padding: 0;
  12.         }
  13.         .box {
  14.             display: flex;
  15.             /* 默认值, 不换行 */
  16.             /* flex-wrap: nowrap; */
  17.          
  18.             /* 让弹性盒子换行 */
  19.             flex-wrap: wrap;
  20.             height: 500px;
  21.             border: 1px solid #000;
  22.         }
  23.         .box div {
  24.             width: 100px;
  25.             height: 100px;
  26.             background-color: pink;
  27.             border: 2px solid green;
  28.         }
  29.     </style>
  30. </head>
  31. <body>
  32.     <div class="box">
  33.         <div>1</div>
  34.         <div>2</div>
  35.         <div>3</div>
  36.         <div>4</div>
  37.         <div>5</div>
  38.         <div>6</div>
  39.         <div>7</div>
  40.         <div>8</div>
  41.     </div>
  42. </body>
  43. </html>
复制代码


调解行对齐方式: align-content

  • 调解换行后, 行的布局(针对换行的盒子)
  • 取值与justify-content基本相同
  • 示例代码
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>弹性盒子换行</title>
  8.     <style>
  9.         * {
  10.             margin: 0;
  11.             padding: 0;
  12.         }
  13.         .box {
  14.             display: flex;
  15.             flex-wrap: wrap;
  16.             /* 调节行对齐方式 */
  17.             align-content: center;
  18.             /* align-content: space-around; */
  19.             /* align-content: space-between; */
  20.             height: 500px;
  21.             border: 1px solid #000;
  22.         }
  23.         .box div {
  24.             width: 100px;
  25.             height: 100px;
  26.             background-color: pink;
  27.             border: 2px solid green;
  28.         }
  29.     </style>
  30. </head>
  31. <body>
  32.     <div class="box">
  33.         <div>1</div>
  34.         <div>2</div>
  35.         <div>3</div>
  36.         <div>4</div>
  37.         <div>5</div>
  38.         <div>6</div>
  39.         <div>7</div>
  40.         <div>8</div>
  41.     </div>
  42. </body>
  43. </html>
复制代码


弹性盒子特点

  • 设置宽高就是宽高的尺寸, 不设置宽高就由内容撑起宽高,
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.   <title>Document</title>
  7.   <style>
  8.     .box {
  9.       background-color: pink;
  10.       display: flex;
  11.       span {
  12.         /* width: 20px; */
  13.         /* height: 20px; */
  14.         background-color: aquamarine;
  15.       }
  16.     }
  17.   </style>
  18. </head>
  19. <body>
  20.   <div class="box">
  21.     <span>1</span>
  22.     <span>2</span>
  23.     <span>3</span>
  24.     <span>4</span>
  25.   </div>
  26. </body>
  27. </html>
复制代码


  • 侧轴设置了主动拉伸并没有设置高度时,会撑满父级
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.   <title>Document</title>
  7.   <style>
  8.     .box {
  9.       display: flex;
  10.       background-color: pink;
  11.       height: 500px;
  12.       span {
  13.         /* 自动拉伸 */
  14.         flex: 1;
  15.         /* 如果设置高度, 以设置的为准, 不设置高度, 就撑满父盒子 */
  16.         /* height: 50px; */
  17.         background-color: aquamarine;
  18.       }
  19.     }
  20.   </style>
  21. </head>
  22. <body>
  23.   <div class="box">
  24.     <span>1</span>
  25.     <span>2</span>
  26.     <span>3</span>
  27.     <span>4</span>
  28.   </div>
  29. </body>
  30. </html>
复制代码


  • 行内元素设置宽高也可以生效
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.   <title>Document</title>
  7.   <style>
  8.     .box {
  9.       background-color: pink;
  10.       display: flex;
  11.       span {
  12.         margin: 10px;
  13.         padding: 10px;
  14.         width: 50px;
  15.         height: 50px;
  16.         background-color: aquamarine;
  17.       }
  18.     }
  19.   </style>
  20. </head>
  21. <body>
  22.   <div class="box">
  23.     <span>1</span>
  24.     <span>2</span>
  25.     <span>3</span>
  26.     <span>4</span>
  27.   </div>
  28. </body>
  29. </html>
复制代码

小兔鲜-订单页

准备环境

新建orders.html作为页面, 引入字体图标文件, base.css用于扫除默认样式

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>确认订单</title>
  8.     <link rel="stylesheet" href="./lib/iconfont/iconfont.css">
  9.     <link rel="stylesheet" href="./css/base.css">
  10.     <link rel="stylesheet" href="./css/orders.css">
  11. </head>
  12. <body>
  13. </body>
  14. </html>
复制代码
  1. * {
  2.   margin: 0;
  3.   padding: 0;
  4.   box-sizing: border-box;
  5. }
  6. body {
  7.   font: 16px/1.5 sans-serif;
  8.   color: #333;
  9.   background-color: #fff;
  10. }
  11. li {
  12.   list-style: none;
  13. }
  14. em,
  15. i {
  16.   font-style: normal;
  17. }
  18. a {
  19.   text-decoration: none;
  20.   color: #333;
  21. }
  22. a:hover {
  23.   color: #5eb69c;
  24. }
  25. img {
  26.   width: 100%;
  27.   vertical-align: middle;
  28. }
  29. input {
  30.   padding: 0;
  31.   border: none;
  32.   outline: none;
  33.   color: #333;
  34. }
  35. button {
  36.   cursor: pointer;
  37. }
  38. /* 清除浮动 */
  39. .clearfix:before,
  40. .clearfix:after {
  41.   content: '';
  42.   display: table;
  43. }
  44. .clearfix:after {
  45.   clear: both;
  46. }
  47. .clearfix {
  48.   *zoom: 1;
  49. }
复制代码

使用像素大厨, 打开移动端设计稿, 调解到2倍图模式, 用于测量尺寸

团体布局

主体内容从上往下, 付出按钮固定在页面底部
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>确认订单</title>
  8.     <link rel="stylesheet" href="./lib/iconfont/iconfont.css">
  9.     <link rel="stylesheet" href="./css/base.css">
  10.     <link rel="stylesheet" href="./css/orders.css">
  11. </head>
  12. <body>
  13.     <!-- 主体内容: 滑动查看 -->
  14.     <div class="main">
  15.         1
  16.     </div>
  17.     <!-- 主体内容: 滑动查看 -->
  18.     <!-- 底部支付: 固定定位 -->
  19.     <div class="pay">
  20.         2
  21.     </div>
  22.     <!-- 底部支付: 固定定位 -->
  23. </body>
  24. </html>
复制代码
  1. body {
  2.     background-color: #f7f7f8;
  3. }
  4. /* 主体内容 */
  5. .main {
  6.     /* 80px: 为了内容不被底部区域盖住 */
  7.     padding: 12px 11px 80px;
  8. }
  9. /* 主体内容 */
  10. /* 底部支付 */
  11. .pay {
  12.     position: fixed;
  13.     left: 0;
  14.     bottom: 0;
  15.     /* 定位脱标后, 默认宽度100%失效, 所以重新设置 */
  16.     width: 100%;
  17.     height: 80px;
  18.     background-color: pink;
  19.     border-top: 1px solid #ededed;
  20. }
  21. /* 底部支付 */
复制代码

底部付出

完成底部付出模块
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>确认订单</title>
  8.     <link rel="stylesheet" href="./lib/iconfont/iconfont.css">
  9.     <link rel="stylesheet" href="./css/base.css">
  10.     <link rel="stylesheet" href="./css/orders.css">
  11. </head>
  12. <body>
  13.     <!-- 主体内容: 滑动查看 -->
  14.     <div class="main">
  15.         1
  16.     </div>
  17.     <!-- 主体内容: 滑动查看 -->
  18.     <!-- 底部支付: 固定定位 -->
  19.     <div class="pay">
  20.         <div class="left">
  21.             合计: <span class="red">¥<i>266.00</i></span>
  22.         </div>
  23.         <div class="right">
  24.             <a href="#">去支付</a>
  25.         </div>
  26.     </div>
  27.     <!-- 底部支付: 固定定位 -->
  28. </body>
  29. </html>
复制代码
  1. body {
  2.     background-color: #f7f7f8;
  3. }
  4. /* 公共样式 */
  5. .red {
  6.     color: #cf4444;
  7. }
  8. /* 主体内容 */
  9. .main {
  10.     /* 80px: 为了内容不被底部区域盖住 */
  11.     padding: 12px 11px 80px;
  12. }
  13. /* 主体内容 */
  14. /* 底部支付 */
  15. .pay {
  16.     position: fixed;
  17.     left: 0;
  18.     bottom: 0;
  19.     display: flex;
  20.     /* 主轴对齐方式 */
  21.     justify-content: space-between;
  22.     /* 侧轴对齐方式 */
  23.     align-items: center;
  24.     /* 定位脱标后, 默认宽度100%失效, 所以重新设置 */
  25.     width: 100%;
  26.     height: 80px;
  27.     padding: 0 11px;
  28.     /* background-color: pink; */
  29.     border-top: 1px solid #ededed;
  30. }
  31. .pay .left {
  32.     font-size: 12px;
  33. }
  34. .pay .left i {
  35.     font-size: 20px;
  36. }
  37. .pay .right a {
  38.     display: block;
  39.     width: 90px;
  40.     height: 35px;
  41.     background-image: linear-gradient(90deg,
  42.             #6fc2aa 5%,
  43.             #54b196 100%);
  44.     border-radius: 3px;
  45.     text-align: center;
  46.     line-height: 35px;
  47.     font-size: 13px;
  48.     color: #fff;
  49. }
  50. /* 底部支付 */
复制代码

地点区域

完成地点模块的布局
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>确认订单</title>
  8.     <link rel="stylesheet" href="./lib/iconfont/iconfont.css">
  9.     <link rel="stylesheet" href="./css/base.css">
  10.     <link rel="stylesheet" href="./css/orders.css">
  11. </head>
  12. <body>
  13.     <!-- 主体内容: 滑动查看 -->
  14.     <div class="main">
  15.         <!-- 用户信息 -->
  16.         <div class="pannel user_msg">
  17.             <div class="location">
  18.                 <i class="iconfont icon-location"></i>
  19.             </div>
  20.             <div class="user">
  21.                 <div class="top">
  22.                     <h5>林丽</h5>
  23.                     <p>18500667882</p>
  24.                 </div>
  25.                 <div class="bottom">北京市 海淀区 中关村软件园 信息科技大厦1号
  26.                     楼410# </div>
  27.             </div>
  28.             <div class="more">
  29.                 <i class="iconfont icon-more"></i>
  30.             </div>
  31.         </div>
  32.         <!-- 用户信息 -->
  33.     </div>
  34.     <!-- 主体内容: 滑动查看 -->
  35.     <!-- 底部支付: 固定定位 -->
  36.     ... ...
  37.     <!-- 底部支付: 固定定位 -->
  38. </body>
  39. </html>
复制代码
  1. body {
  2.     background-color: #f7f7f8;
  3. }
  4. /* 公共样式 */
  5. .red {
  6.     color: #cf4444;
  7. }
  8. .pannel {
  9.     margin-bottom: 10px;
  10.     background-color: #fff;
  11.     border-radius: 5px;
  12. }
  13. /* 主体内容 */
  14. .main {
  15.     /* 80px: 为了内容不被底部区域盖住 */
  16.     padding: 12px 11px 80px;
  17. }
  18. /* 主体内容 */
  19. .main {
  20.     /* 80px: 为了内容不被底部区域盖住 */
  21.     padding: 12px 11px 80px;
  22. }
  23. /* 用户信息 */
  24. .user_msg {
  25.     display: flex;
  26.     align-items: center;
  27.     padding: 15px 0 15px 11px;
  28. }
  29. .user_msg .location {
  30.     width: 30px;
  31.     height: 30px;
  32.     margin-right: 10px;
  33.     background-image: linear-gradient(90deg,
  34.             #6fc2aa 5%,
  35.             #54b196 100%);
  36.     border-radius: 50%;
  37.     text-align: center;
  38.     line-height: 30px;
  39.     color: #fff;
  40. }
  41. .user_msg .user {
  42.     flex: 1;
  43. }
  44. .user_msg .user .top {
  45.     display: flex;
  46. }
  47. .user_msg .user .top h5 {
  48.     width: 55px;
  49.     font-size: 15px;
  50.     font-weight: 400;
  51. }
  52. .user_msg .user .top p {
  53.     font-size: 13px;
  54. }
  55. .user_msg .user .bottom {
  56.     margin-top: 5px;
  57.     font-size: 12px;
  58. }
  59. .user_msg .more {
  60.     width: 44px;
  61.     height: 44px;
  62.     /* background-color: pink; */
  63.     text-align: center;
  64.     line-height: 44px;
  65.     color: #808080;
  66. }
  67. /* 主体内容 */
复制代码

商品区域

完成商品区域的布局
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>确认订单</title>
  8.     <link rel="stylesheet" href="./lib/iconfont/iconfont.css">
  9.     <link rel="stylesheet" href="./css/base.css">
  10.     <link rel="stylesheet" href="./css/orders.css">
  11. </head>
  12. <body>
  13.     <!-- 主体内容: 滑动查看 -->
  14.     <div class="main">
  15.         <!-- 用户信息 -->
  16.         ... ...
  17.         <!-- 用户信息 -->
  18.         <!-- 商品 -->
  19.         <div class="pannel goods">
  20.             <div class="pic">
  21.                 <a href="#"><img src="./uploads/pic.png" alt=""></a>
  22.             </div>
  23.             <div class="info">
  24.                 <h5>康尔贝 非接触式红外体温仪
  25.                     领券立减30元 婴儿级材质 测温…</h5>
  26.                 <p><span>粉色</span>   <span>红外体温计</span></p>
  27.                 <div class="price">
  28.                     <span class="red">¥ <i>266</i> </span>
  29.                     <span>¥299</span>
  30.                 </div>
  31.             </div>
  32.             <div class="count">
  33.                 <i class="iconfont icon-x"></i>
  34.                 <span>1</span>
  35.             </div>
  36.         </div>
  37.         <!-- 商品 -->
  38.     </div>
  39.     <!-- 主体内容: 滑动查看 -->
  40.     <!-- 底部支付: 固定定位 -->
  41.     ...
  42.     <!-- 底部支付: 固定定位 -->
  43. </body>
  44. </html>
复制代码
  1. body {
  2.     background-color: #f7f7f8;
  3. }
  4. /* 公共样式 */
  5. .red {
  6.     color: #cf4444;
  7. }
  8. .pannel {
  9.     margin-bottom: 10px;
  10.     background-color: #fff;
  11.     border-radius: 5px;
  12. }
  13. /* 主体内容 */
  14. .main {
  15.     /* 80px: 为了内容不被底部区域盖住 */
  16.     padding: 12px 11px 80px;
  17. }
  18. /* 商品 */
  19. .goods {
  20.     display: flex;
  21.     padding: 11px 0 11px 11px;
  22. }
  23. .goods .pic {
  24.     width: 85px;
  25.     height: 85px;
  26.     margin-right: 10px;
  27. }
  28. .goods .info {
  29.     flex: 1;
  30. }
  31. .goods .info h5 {
  32.     font-size: 13px;
  33.     color: #262626;
  34.     font-weight: 400;
  35. }
  36. .goods .info p {
  37.     width: 95px;
  38.     height: 20px;
  39.     margin: 5px 0;
  40.     background-color: #f7f7f8;
  41.     font-size: 12px;
  42.     color: #888;
  43. }
  44. .goods .info p span:first-child {
  45.     margin-right: 5px;
  46. }
  47. .goods .info .price {
  48.     font-size: 12px;
  49. }
  50. .goods .info .price i {
  51.     font-size: 16px;
  52. }
  53. .goods .info .price span:last-child {
  54.     margin-left: 5px;
  55.     color: #999;
  56.     text-decoration: line-through;
  57. }
  58. .goods .count {
  59.     width: 44px;
  60.     height: 44px;
  61.     /* background-color: pink; */
  62.     text-align: center;
  63.     line-height: 44px;
  64. }
  65. /* 主体内容 */
复制代码

配送信息

完成配送信息的布局
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>确认订单</title>
  8.     <link rel="stylesheet" href="./lib/iconfont/iconfont.css">
  9.     <link rel="stylesheet" href="./css/base.css">
  10.     <link rel="stylesheet" href="./css/orders.css">
  11. </head>
  12. <body>
  13.     <!-- 主体内容: 滑动查看 -->
  14.     <div class="main">
  15.         <!-- 用户信息 -->
  16.         ... ...
  17.         <!-- 用户信息 -->
  18.         <!-- 商品 -->
  19.         ... ...
  20.         <!-- 商品 -->
  21.         <!-- 其他信息 -->
  22.         <!-- div.pannel   rest   -->
  23.         <!-- header  nav  section footer -->
  24.         <section class="pannel rest">
  25.             <div>
  26.                 <h5>配送方式</h5>
  27.                 <p>顺丰快递</p>
  28.             </div>
  29.             <div>
  30.                 <h5>配送方式</h5>
  31.                 <p>顺丰快递</p>
  32.             </div>
  33.             <div>
  34.                 <h5>配送方式</h5>
  35.                 <p>顺丰快递</p>
  36.             </div>
  37.         </section>
  38.         <!-- 其他信息 -->
  39.     </div>
  40.     <!-- 主体内容: 滑动查看 -->
  41.     <!-- 底部支付: 固定定位 -->
  42.      ... ...
  43.     <!-- 底部支付: 固定定位 -->
  44. </body>
  45. </html>
复制代码
  1. body {
  2.     background-color: #f7f7f8;
  3. }
  4. /* 公共样式 */
  5. .red {
  6.     color: #cf4444;
  7. }
  8. .pannel {
  9.     margin-bottom: 10px;
  10.     background-color: #fff;
  11.     border-radius: 5px;
  12. }
  13. /* 其他信息 */
  14. .rest {
  15.     padding: 15px;
  16. }
  17. .rest div {
  18.     display: flex;
  19.     margin-bottom: 30px;
  20. }
  21. .rest div:last-child {
  22.     margin-bottom: 0;
  23. }
  24. /* 找到第一个和第三个div设置主轴对齐方式 */
  25. .rest div:nth-child(2n+1) {
  26.     justify-content: space-between;
  27. }
  28. /* 第二行标题和p之间的距离 */
  29. .rest div:nth-child(2) h5 {
  30.     margin-right: 20px;
  31. }
  32. .rest h5,
  33. .rest p{
  34.     font-size: 13px;
  35.     color: #262626;
  36.     font-weight: 400;
  37. }
  38. /* .rest p {
  39.     font-size: 13px;
  40.     color: #262626;
  41. } */
  42. .rest div:nth-child(2) p {
  43.     font-size: 12px;
  44.     color: #989898;
  45. }
  46. /* 主体内容 */
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
继续阅读请点击广告

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

快速回复 返回顶部 返回列表