Blogger Information
Blog 5
fans 0
comment 0
visits 3090
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex容器中的四个属性的功能演示
加油2021
Original
525 people have browsed it

实例演示flex容器中的四个属性的功能,参数,以及作用

flex容器中的四个属性的功能,参数,以及作用

flex-flow:主轴方向(row|colum) 是否换行(wrap|nowrap)

justify-content:项目在主轴上的对齐方式

align-items:项目在交叉轴上的对齐方式

align-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>flex</title>
  8. </head>
  9. <style>
  10. :root {
  11. font-size: 10px;
  12. }
  13. * {
  14. padding: 0;
  15. margin: 0;
  16. box-sizing: border-box;
  17. }
  18. html {
  19. font-size: 16px;
  20. }
  21. .content,
  22. .content2,
  23. .content3,
  24. .content4,
  25. .content5,
  26. .content6 {
  27. display: none !important;
  28. }
  29. .content {
  30. display: flex;
  31. /* 主轴水平方向 不换行 */
  32. flex-flow: row nowrap;
  33. }
  34. .content2 {
  35. margin-top: 10rem;
  36. display: flex;
  37. /* 主轴垂直方向 不换行 */
  38. flex-flow: column nowrap;
  39. }
  40. .content3 {
  41. margin-top: 10rem;
  42. display: flex;
  43. /* 主轴水平方向 换行 */
  44. flex-flow: row wrap;
  45. }
  46. .content4 {
  47. margin-top: 10rem;
  48. display: flex;
  49. /* 主轴垂直方向 换行 */
  50. flex-flow: column wrap;
  51. height: 20rem;
  52. }
  53. .content .item,
  54. .content2 .item,
  55. .content3 .item,
  56. .content4 .item,
  57. .content5 .item,
  58. .content6 .item,
  59. .content7 .item {
  60. height: 5rem;
  61. padding: 1rem;
  62. }
  63. .content5 {
  64. display: flex;
  65. /* 位于容器开头 */
  66. justify-content: flex-start;
  67. /* 位于容器的结尾 */
  68. justify-content: flex-end;
  69. /* 位于容器中间 */
  70. justify-content: center;
  71. /* 分散对齐 */
  72. justify-content: space-around;
  73. /* 两端对齐 */
  74. justify-content: space-between;
  75. /* 平均对齐 */
  76. justify-content: space-evenly;
  77. }
  78. .content6 {
  79. display: flex;
  80. height: 20rem;
  81. /* 默认会充满单行容器的高度 */
  82. align-items: stretch;
  83. /* 交叉轴的起点对齐 */
  84. align-items: flex-start;
  85. /* 交叉轴的终点对齐 */
  86. align-items: flex-end;
  87. /* 交叉轴的中点对齐 */
  88. align-items: center;
  89. }
  90. .content7 {
  91. display: flex;
  92. height: 20rem;
  93. flex-flow: row wrap;
  94. /* 与交叉轴的起点对齐 */
  95. align-content: flex-start;
  96. /* 与交叉轴的终点对齐 */
  97. align-content: flex-end;
  98. /* 与交叉轴的中点对齐 */
  99. align-content: center;
  100. /* 与交叉轴两端对齐,轴线之间的间隔平均分布 */
  101. align-content: space-between;
  102. align-content: space-around;
  103. align-content: stretch;
  104. }
  105. </style>
  106. <body>
  107. <!-- 主轴水平方向 不换行 -->
  108. <div class="content">
  109. <div class="item">item1</div>
  110. <div class="item">item2</div>
  111. <div class="item">item3</div>
  112. <div class="item">item4</div>
  113. </div>
  114. <!-- 主轴垂直方向 不换行 -->
  115. <div class="content2">
  116. <div class="item">item1</div>
  117. <div class="item">item2</div>
  118. <div class="item">item3</div>
  119. <div class="item">item4</div>
  120. </div>
  121. <!-- 主轴水平方向 换行 -->
  122. <div class="content3">
  123. <div class="item">item1</div>
  124. <div class="item">item2</div>
  125. <div class="item">item3</div>
  126. <div class="item">item4</div>
  127. <div class="item">item5</div>
  128. <div class="item">item6</div>
  129. <div class="item">item7</div>
  130. <div class="item">item8</div>
  131. <div class="item">item9</div>
  132. </div>
  133. <!-- 主轴垂直方向 换行 -->
  134. <div class="content4">
  135. <div class="item">item1</div>
  136. <div class="item">item2</div>
  137. <div class="item">item3</div>
  138. <div class="item">item4</div>
  139. <div class="item">item5</div>
  140. <div class="item">item6</div>
  141. <div class="item">item7</div>
  142. <div class="item">item8</div>
  143. <div class="item">item9</div>
  144. </div>
  145. <!-- justify-content 属性 项目在主轴上的对齐方式 -->
  146. <div class="content5">
  147. <div class="item">item1</div>
  148. <div class="item">item2</div>
  149. <div class="item">item3</div>
  150. <div class="item">item4</div>
  151. <div class="item">item5</div>
  152. </div>
  153. <!-- align-items属性 项目在交叉轴上的对齐方式 -->
  154. <div class="content6">
  155. <div class="item">item1</div>
  156. <div class="item">item2</div>
  157. <div class="item">item3</div>
  158. <div class="item">item4</div>
  159. <div class="item">item5</div>
  160. </div>
  161. <!-- align-content属性 项目在多行容器中的对齐方式 -->
  162. <div class="content7">
  163. <div class="item">item1</div>
  164. <div class="item">item2</div>
  165. <div class="item">item3</div>
  166. <div class="item">item4</div>
  167. <div class="item">item5</div>
  168. <div class="item">item6</div>
  169. <div class="item">item7</div>
  170. </div>
  171. </body>
  172. </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