flex项目上的三个属性

flex:项目的缩放比例与基准宽度
align-self:单个项目在交叉轴上的对齐方式
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>Document</title>
  8. <style>
  9. * {
  10. box-sizing: border-box;
  11. }
  12. :root {
  13. font-size: 10px;
  14. }
  15. body {
  16. font-size: 1.6rem;
  17. }
  18. .container {
  19. display: flex;
  20. height: 100vh;
  21. border: 2px solid #000000;
  22. }
  23. .container > .item {
  24. padding: 3rem;
  25. /* height: 5rem; */
  26. /* width: 10rem; */
  27. background-color: cyan;
  28. border: 1px solid rosybrown;
  29. /* flex:项目的缩放比例与基准宽度 */
  30. /* flex: 放大因子 收缩因子 项目在主轴上的基准宽度 */
  31. /* 默认,禁止放大,允许收缩,宽度自动 */
  32. flex: 0 1 auto;
  33. /* 简写 */
  34. flex: initial;
  35. /* 允许放大和收缩 */
  36. flex: 1 1 auto;
  37. /* 简写 */
  38. flex: auto;
  39. /* 禁止放大和收缩,一般用于PC布局 */
  40. flex: 0 0 auto;
  41. /* 简写 */
  42. flex: none;
  43. }
  44. /* 案例,要求第2个项目的宽度是其他项目的两倍 */
  45. .container > .item:nth-of-type(2) {
  46. flex: 2 1 auto;
  47. }
  48. .container > .item:first-of-type,
  49. .container > .item:last-of-type {
  50. flex: 1 1 auto;
  51. }
  52. /* align-self:单个项目在交叉轴上的对齐方式 */
  53. .container > .item:nth-of-type(2) {
  54. /* 默认拉伸 */
  55. align-self: stretch;
  56. /* 起始线 */
  57. align-self: flex-start;
  58. }
  59. .container > .item:first-of-type {
  60. /* 终止线 */
  61. align-self: flex-end;
  62. }
  63. .container > .item:last-of-type {
  64. /* 居中 */
  65. align-self: center;
  66. }
  67. /* order:项目在主轴上排列顺序 */
  68. .container > .item:nth-of-type(2) {
  69. /* 默认序号越小越靠前,越大越靠后 */
  70. order: 3;
  71. }
  72. .container > .item:first-of-type {
  73. ordre: 2;
  74. }
  75. .container > .item:last-of-type {
  76. order: 1;
  77. }
  78. </style>
  79. </head>
  80. <body>
  81. <div class="container">
  82. <div class="item">item1</div>
  83. <div class="item">item2</div>
  84. <div class="item">item3</div>
  85. </div>
  86. </body>
  87. </html>

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

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. <link rel="stylesheet" href="static/css/reset.css" />
  8. <link rel="stylesheet" href="static/icon-font/iconfont.css" />
  9. <link rel="stylesheet" href="static/css/index.css" />
  10. <link rel="stylesheet" href="static/css/header.css" />
  11. <link rel="stylesheet" href="static/css/footer.css" />
  12. <title>Document</title>
  13. </head>
  14. <body>
  15. <header>
  16. <!-- 菜单栏 -->
  17. <div class="caidan iconfont icon-menu"></div>
  18. <!-- 搜索框 -->
  19. <div class="search">
  20. <div class="logo">JD</div>
  21. <div class="fangda iconfont icon-search"></div>
  22. <input type="text" class="words" value="保险箱" />
  23. </div>
  24. <!-- 登录按钮 -->
  25. <a href="" class="denglu">登录</a>
  26. </header>
  27. <main></main>
  28. <footer>
  29. <div>
  30. <div class="iconfont icon-home"></div>
  31. <span>主页</span>
  32. </div>
  33. <div>
  34. <div class="iconfont icon-layers"></div>
  35. <span>分类</span>
  36. </div>
  37. <div>
  38. <div class="iconfont icon-kehuguanli"></div>
  39. <span>京喜</span>
  40. </div>
  41. <div>
  42. <div class="iconfont icon-shopping-cart"></div>
  43. <span>购物车</span>
  44. </div>
  45. <div>
  46. <div class="iconfont icon-user"></div>
  47. <span>未登录</span>
  48. </div>
  49. </footer>
  50. </body>
  51. </html>

初始化

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. li {
  7. list-style: none;
  8. }
  9. a {
  10. color: #7b7b7b;
  11. text-decoration: none;
  12. }
  13. body {
  14. background-color: #f6f6f6;
  15. }
  16. html {
  17. font-size: 10px;
  18. }
  19. @media screen and (min-width: 480px) {
  20. html {
  21. font-size: 12px;
  22. }
  23. }
  24. @media screen and (min-width: 640px) {
  25. html {
  26. font-size: 14px;
  27. }
  28. }
  29. @media screen and (min-width: 720px) {
  30. html {
  31. font-size: 16px;
  32. }
  33. }

index.css

  1. header {
  2. background-color: #e43130;
  3. color: #fff;
  4. height: 4.4rem;
  5. position: fixed;
  6. left: 0;
  7. top: 0;
  8. right: 0;
  9. z-index: 100;
  10. }
  11. main {
  12. position: absolute;
  13. top: 4.4rem;
  14. bottom: 4.4rem;
  15. }
  16. footer {
  17. background-color: #fafafa;
  18. color: #666;
  19. height: 4.4rem;
  20. position: fixed;
  21. left: 0;
  22. bottom: 0;
  23. right: 0;
  24. z-index: 100;
  25. }

header.css

  1. header {
  2. display: flex;
  3. flex-flow: row nowrap;
  4. align-items: center;
  5. }
  6. header .caidan {
  7. flex: 1;
  8. text-align: center;
  9. font-size: 2.5rem;
  10. }
  11. header .search {
  12. flex: 5;
  13. background-color: #ffffff;
  14. border-radius: 3rem;
  15. display: flex;
  16. padding: 0.35rem 0.5rem;
  17. }
  18. header .search .logo {
  19. font-size: 1.8rem;
  20. color: #e43130;
  21. flex: 0 1 4rem;
  22. text-align: center;
  23. }
  24. header .search .fangda {
  25. color: #ccc;
  26. flex: 0 1 4rem;
  27. border-left: 1px solid;
  28. align-self: center;
  29. text-align: center;
  30. }
  31. header .search .words {
  32. flex: auto;
  33. border: none;
  34. outline: none;
  35. color: #aaa;
  36. }
  37. header .denglu {
  38. flex: 1;
  39. color: #fff;
  40. text-align: center;
  41. font-size: 1.4rem;
  42. }

footer.css

  1. footer {
  2. display: flex;
  3. justify-content: space-around;
  4. text-align: center;
  5. align-items: center;
  6. }
  7. footer div .iconfont {
  8. font-size: 1.4rem;
  9. }
  10. footer div span {
  11. font-size: 0.8rem;
  12. }

更多相关文章

  1. 拥抱人工智能竞赛,但不要忽略项目审计
  2. flex项目上的三个属性及移动商城首页的页眉和页脚的布局
  3. 一个云迁移项目应该有哪些文档
  4. 0325作业
  5. 210325 CSS flex布局 项目属性
  6. CSS3中的box-sizing属性实例详解
  7. css之flex项目属性与商城首页布局实战
  8. flex项目属性,实战案例。
  9. 移动商城首页的页眉和页脚的布局和flex项目三个属性

随机推荐

  1. C#开发Android应用实战——使用Mono for
  2. android json实现网络请求 和普通的http
  3. Android屏幕元素层次结构
  4. Android(安卓)Scroller简单用法
  5. android 5.0新特性
  6. Android之简易天气预报小应用(xml解析练手
  7. duplicate files during packaging of ap
  8. Android系统启动
  9. Android中的广播也定向
  10. 实现android启动界面字体的动画效果