flex布局 多行

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. box-sizing: border-box;
  13. }
  14. html {
  15. font-size: 10px;
  16. }
  17. body {
  18. font-size: 1.6rem;
  19. }
  20. .container {
  21. display: flex;
  22. height: 20rem;
  23. /* width: 5em; */
  24. boreder: 1px solid black;
  25. }
  26. .container > .item {
  27. width: 10rem;
  28. background-color: chartreuse;
  29. border: 1px solid black;
  30. }
  31. /* 默认 */
  32. .container {
  33. flex-flow: row wrap;
  34. }
  35. /* .container {
  36. flex-flow: row wrap;
  37. } */
  38. </style>
  39. </head>
  40. <body>
  41. <div class="container">
  42. <item class="item">item1</item>
  43. <item class="item">item2</item>
  44. <item class="item">item3</item>
  45. <item class="item">item4</item>
  46. <item class="item">item5</item>
  47. <item class="item">item6</item>
  48. <item class="item">item7</item>
  49. <item class="item">item8</item>
  50. </div>
  51. </body>
  52. </html>

列布局

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. box-sizing: border-box;
  13. }
  14. html {
  15. font-size: 10px;
  16. }
  17. body {
  18. font-size: 1.6rem;
  19. }
  20. .container {
  21. display: flex;
  22. height: 20rem;
  23. /* width: 5em; */
  24. boreder: 1px solid black;
  25. }
  26. .container > .item {
  27. width: 10rem;
  28. height: 5rem;
  29. background-color: chartreuse;
  30. border: 1px solid black;
  31. }
  32. /* 默认 */
  33. .container {
  34. flex-flow: column wrap;
  35. }
  36. /* .container {
  37. flex-flow: row wrap;
  38. } */
  39. </style>
  40. </head>
  41. <body>
  42. <div class="container">
  43. <item class="item">item1</item>
  44. <item class="item">item2</item>
  45. <item class="item">item3</item>
  46. <item class="item">item4</item>
  47. <item class="item">item5</item>
  48. <item class="item">item6</item>
  49. <item class="item">item7</item>
  50. <item class="item">item8</item>
  51. </div>
  52. </body>
  53. </html>

手机页面

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. </head>
  9. <style>
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. box-sizing: border-box;
  14. }
  15. html {
  16. font-size: 10px;
  17. }
  18. body {
  19. font-size: 1.6rem;
  20. }
  21. .container {
  22. display: flex;
  23. height: 100vh;
  24. border: 1px solid #000;
  25. flex-flow: column nowrap;
  26. }
  27. .container > .item {
  28. height: 5rem;
  29. width: 10rem;
  30. border: 1px solid #000;
  31. background-color: red;
  32. }
  33. .container > .item:nth-of-type(1),
  34. .container > .item:nth-of-type(3) {
  35. height: 5vh;
  36. }
  37. .container > .item:nth-of-type(2) {
  38. height: 90vh;
  39. }
  40. </style>
  41. <body>
  42. <div class="container">
  43. <div class="item">item1</div>
  44. <div class="item">item2</div>
  45. <div class="item">item3</div>
  46. </div>
  47. </body>
  48. </html>

项目对齐方式

1.整体居中对齐

2.整体末尾对齐

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. box-sizing: border-box;
  13. }
  14. :root {
  15. font-size: 10px;
  16. }
  17. body {
  18. font-size: 1.6rem;
  19. }
  20. .container {
  21. display: flex;
  22. height: 20rem;
  23. border: 1px solid blue;
  24. justify-content: end;
  25. /* justify-content: center; */
  26. }
  27. .container .item {
  28. width: 5rem;
  29. background-color: red;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div class="container">
  35. <div class="item">item1</div>
  36. <div class="item">item2</div>
  37. <div class="item">item3</div>
  38. <div class="item">item4</div>
  39. </div>
  40. </body>
  41. </html>

交叉轴对齐方式

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. box-sizing: border-box;
  13. }
  14. :root {
  15. font-size: 10px;
  16. }
  17. body {
  18. font-size: 1.6rem;
  19. }
  20. .container {
  21. display: flex;
  22. height: 20rem;
  23. border: 1px solid blue;
  24. justify-content: space-evenly;
  25. /* justify-content: end; */
  26. /* justify-content: center; */
  27. align-items: center;
  28. }
  29. .container .item {
  30. /* width: 5rem; */
  31. background-color: red;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div class="container">
  37. <div class="item">item1</div>
  38. <div class="item">item2</div>
  39. <div class="item">item3</div>
  40. <div class="item">item4</div>
  41. </div>
  42. </body>
  43. </html>
  44. 3.多行文本布局
  45. ![](https://img.php.cn/upload/image/138/224/814/1616730514845755.png)
  46. ```html
  47. <!DOCTYPE html>
  48. <html lang="zh-CN">
  49. <head>
  50. <meta charset="UTF-8" />
  51. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  52. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  53. <title>flex容器属性</title>
  54. <style>
  55. * {
  56. margin: 0;
  57. padding: 0;
  58. box-sizing: border-box;
  59. }
  60. :root {
  61. font-size: 10px;
  62. }
  63. body {
  64. font-size: 1.6rem;
  65. }
  66. .container {
  67. display: flex;
  68. flex-flow: row wrap;
  69. height: 20rem;
  70. border: 1px solid blue;
  71. /* justify-content: space-evenly; */
  72. /* justify-content: end; */
  73. /* justify-content: center; */
  74. /* align-items: center; */
  75. align-content: flex-end;
  76. align-content: flex-start;
  77. align-content: center;
  78. }
  79. .container .item {
  80. /* height: 3rem; */
  81. width: 5rem;
  82. background-color: red;
  83. }
  84. </style>
  85. </head>
  86. <body>
  87. <div class="container">
  88. <div class="item">item1</div>
  89. <div class="item">item2</div>
  90. <div class="item">item3</div>
  91. <div class="item">item5</div>
  92. <div class="item">item6</div>
  93. <div class="item">item7</div>
  94. <div class="item">item8</div>
  95. <div class="item">item9</div>
  96. <div class="item">item10</div>
  97. <div class="item">item11</div>
  98. <div class="item">item12</div>
  99. </div>
  100. </body>
  101. </html>

更多相关文章

  1. flex容器中的四个属性的功能演示
  2. flex容器属性的功能,参数,以及作用
  3. css-flex布局
  4. 3.24实例演示flex容器中的四个属性的功能,参数,以及作用
  5. css之flex容器
  6. 【CSS入门】前端布局神器Flex弹性盒模型详解及适用场景(建议收藏
  7. 0324作业-flex布局
  8. flex布局:flex容器中的四个属性的功能,参数,以及作用
  9. 在苹果Mac上的“邮件”中如何使用列布局?

随机推荐

  1. UI控件之显示文本控件TextView(上)
  2. 研究了有一个月android下手机录制视频做
  3. Android—android与js交互以及相互传参
  4. 登录时旋转等待效果
  5. Android 博客目录整理
  6. 从NDK在非Root手机上的调试原理探讨Andro
  7. Android开发之一些问题的解决办法
  8. android实现进程注入
  9. 适用于 AIDE - Android Java IDE 的幸运
  10. Android向服务器传接和接收数据的方法汇