Blogger Information
Blog 11
fans 0
comment 0
visits 6559
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex项目上的三个属性及移动商城首页的页眉和页脚的布局
Ghcᝰ
Original
558 people have browsed it

flex项目上的三个属性

1.项目的缩放比例与基准宽度

flex属性用法及演示:
  • a) 默认值,禁止放大,允许收缩,宽度自动
    0 1 auto
  • b) 允许放大和收缩
    1 1 auto
  • c) 禁止放大和收缩,这个属性这是通常用于PC布局
    0 0 none
    下面演示允许缩放功能
    允许放大缩小宽度自适应
  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. root: {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. font-size: 10px;
  14. }
  15. body {
  16. font-size: 1.6rem;
  17. }
  18. .box {
  19. display: flex;
  20. border: solid 1px red;
  21. height: 80vh;
  22. }
  23. .item {
  24. width: 8rem;
  25. /* 允许放大,缩小,宽度自适应 */
  26. flex: 1 1 auto;
  27. border: aquamarine 1px solid;
  28. }
  29. .item:nth-of-type(1) {
  30. background-color: red;
  31. }
  32. .item:nth-of-type(2) {
  33. background-color: yellow;
  34. }
  35. .item:nth-of-type(3) {
  36. background-color: blue;
  37. }
  38. .item:nth-of-type(4) {
  39. background-color: greenyellow;
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <div class="box">
  45. <div class="item">item1</div>
  46. <div class="item">item2</div>
  47. <div class="item">item3</div>
  48. <div class="item">item4</div>
  49. </div>
  50. </body>
  51. </html>

2.单个项目在交叉轴上的对齐方式

align-self属性用法及演示:
  • a) 默认值:stretch 拉伸
  • b) flex-start 起始线(交叉轴对齐)
  • c) flex-end 终止线(交叉轴对齐)
  • d) center 居中对齐
    下面演示flex-end功能
    交叉轴终止线对齐
  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. root: {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. font-size: 10px;
  14. }
  15. body {
  16. font-size: 1.6rem;
  17. }
  18. .box {
  19. display: flex;
  20. border: solid 1px red;
  21. height: 80vh;
  22. /* 主轴垂直不换行 */
  23. /* flex-flow: column nowrap; */
  24. }
  25. .item {
  26. width: 8rem;
  27. /* 底部对齐 */
  28. align-self: flex-end;
  29. border: aquamarine 1px solid;
  30. }
  31. .item:nth-of-type(1) {
  32. background-color: red;
  33. }
  34. .item:nth-of-type(2) {
  35. background-color: yellow;
  36. }
  37. .item:nth-of-type(3) {
  38. background-color: blue;
  39. }
  40. .item:nth-of-type(4) {
  41. background-color: greenyellow;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <div class="box">
  47. <div class="item">item1</div>
  48. <div class="item">item2</div>
  49. <div class="item">item3</div>
  50. <div class="item">item4</div>
  51. </div>
  52. </body>
  53. </html>

3.项目在主轴上排列顺序

order属性用法及演示:
  • a) 显示顺序:按书写的序号越小越靠前,越大越靠后
    下面演示order设置倒序功能
    使用order属性设置项目倒叙排列
  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. root: {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. font-size: 10px;
  14. }
  15. body {
  16. font-size: 1.6rem;
  17. }
  18. .box {
  19. display: flex;
  20. border: solid 1px red;
  21. height: 80vh;
  22. /* 主轴垂直不换行 */
  23. /* flex-flow: column nowrap; */
  24. }
  25. .item {
  26. width: 8rem;
  27. /* 居中对齐 */
  28. align-self: center;
  29. border: aquamarine 1px solid;
  30. }
  31. /* 设置倒序 */
  32. .item:nth-of-type(1) {
  33. background-color: red;
  34. order: 4;
  35. }
  36. .item:nth-of-type(2) {
  37. background-color: yellow;
  38. order: 3;
  39. }
  40. .item:nth-of-type(3) {
  41. background-color: blue;
  42. order: 2;
  43. }
  44. .item:nth-of-type(4) {
  45. background-color: greenyellow;
  46. order: 1;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div class="box">
  52. <div class="item">item1</div>
  53. <div class="item">item2</div>
  54. <div class="item">item3</div>
  55. <div class="item">item4</div>
  56. </div>
  57. </body>
  58. </html>

移动商城首页的页眉和页脚的布局

页头页脚布局

  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. <link rel="stylesheet" href="static/css/index.css">
  9. <link rel="stylesheet" href="static/icon-font/iconfont.css">
  10. <link rel="stylesheet" href="static/css/header.css">
  11. <link rel="stylesheet" href="static/css/footer.css">
  12. </head>
  13. <body>
  14. <!-- 页眉 -->
  15. <div class="header">
  16. <!-- 菜单 -->
  17. <div class="menu iconfont icon-menu"></div>
  18. <!-- 搜索框 -->
  19. <div class="search">
  20. <div class="logo">
  21. JD
  22. </div>
  23. <div class="zoom iconfont icon-search"></div>
  24. <input type="text" class="words" value="移动硬盘500G">
  25. </div>
  26. <!-- 登录按钮 -->
  27. <a href="" class="login">登录</a>
  28. </div>
  29. <div class="main">
  30. 主体
  31. </div>
  32. <div class="footer">
  33. <div>
  34. <div class="iconfont icon-home"></div>
  35. <span>首页</span>
  36. </div>
  37. <div>
  38. <div class="iconfont icon-layers"></div>
  39. <span>分类</span>
  40. </div>
  41. <div>
  42. <div class="iconfont icon-Group-"></div>
  43. <span>惊喜</span>
  44. </div>
  45. <div>
  46. <div class="iconfont icon-shopping-cart
  47. "></div>
  48. <span>购物车</span>
  49. </div>
  50. <div>
  51. <div class="iconfont icon-user"></div>
  52. <span>未登录</span>
  53. </div>
  54. </div>
  55. </body>
  56. </html>
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post