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 type="text/css">
  9. * {
  10. padding: 0;
  11. margin: 0;
  12. box-sizing: border-box;
  13. }
  14. /* 设置元素html字体为10px */
  15. :root {
  16. font-size: 10px;
  17. }
  18. /* body字体为16px */
  19. body {
  20. font-size: 1.6rem;
  21. }
  22. /* 定义一个flex容器
  23. #box {
  24. border: 1px solid;
  25. width: 30em;
  26. height: 30em;
  27. 转变为flex容器
  28. display: flex;
  29. 设置为水平方向排列,不换行元素
  30. flex-flow: row nowrap;
  31. }*/
  32. /* #box {
  33. border: 1px solid;
  34. width: 30em;
  35. height: 30em;
  36. display: flex;
  37. 设置为水平方向排列,会进行换行
  38. flex-flow: row wrap;
  39. } */
  40. /* #box {
  41. width: 30em;
  42. height: 30em;
  43. display: flex;
  44. 设置为垂直方向排列,不会进行换行
  45. flex-flow: column nowrap;
  46. } */
  47. /* #box {
  48. width: 30em;
  49. height: 30em;
  50. display: flex;
  51. 设置为垂直方向排列,会进行换行
  52. flex-flow: column wrap;
  53. } */
  54. /* #box {
  55. width: 30em;
  56. height: 30em;
  57. display: flex;
  58. 设置项目在主轴上的对齐方式,默认起始线。
  59. justify-content: flex-start;
  60. } */
  61. /* #box {
  62. width: 30em;
  63. height: 30em;
  64. display: flex;
  65. 设置项目在主轴上的对齐方式,终止线。
  66. justify-content: flex-end;
  67. } */
  68. /* #box {
  69. width: 30em;
  70. height: 30em;
  71. display: flex;
  72. 设置项目在主轴上的对齐方式,居中。
  73. justify-content: center;
  74. } */
  75. /* #box {
  76. width: 30em;
  77. height: 30em;
  78. display: flex;
  79. 设置项目在主轴上的对齐方式,两端对齐。
  80. justify-content: space-between;
  81. } */
  82. /* #box {
  83. width: 30em;
  84. height: 30em;
  85. display: flex;
  86. 设置项目在主轴上的对齐方式,分散对齐。
  87. justify-content: space-around;
  88. } */
  89. /* #box {
  90. width: 30em;
  91. height: 30em;
  92. display: flex;
  93. 设置项目在主轴上的对齐方式,平均对齐。
  94. justify-content: space-evenly;
  95. } */
  96. /*
  97. #box {
  98. width: 30em;
  99. height: 30em;
  100. display: flex;
  101. 设置项目在交叉轴的对齐方式,默认拉伸。
  102. align-items: stretch;
  103. } */
  104. /* #box {
  105. width: 30em;
  106. height: 30em;
  107. display: flex;
  108. 设置项目在交叉轴的对齐方式,起始线。
  109. align-items: flex-start;
  110. } */
  111. /* #box {
  112. width: 30em;
  113. height: 30em;
  114. display: flex;
  115. 设置项目在交叉轴的对齐方式,终止线。
  116. align-items: flex-end;
  117. } */
  118. /* #box {
  119. width: 30em;
  120. height: 30em;
  121. display: flex;
  122. 设置项目在交叉轴的对齐方式,居中。
  123. align-items: center;
  124. } */
  125. #box {
  126. width: 30em;
  127. height: 30em;
  128. display: flex;
  129. /* 设置项目在多行容器交叉轴上的对齐方式,起始线。 */
  130. flex-flow: row wrap;
  131. align-content: flex-start;
  132. }
  133. #box > .boxder {
  134. border: 1px solid;
  135. background: lightgreen;
  136. width: 5em;
  137. height: 5em;
  138. }
  139. </style>
  140. </head>
  141. <body>
  142. <div id="box">
  143. <div class="boxder">项目1</div>
  144. <div class="boxder">项目2</div>
  145. <div class="boxder">项目3</div>
  146. <div class="boxder">项目4</div>
  147. <div class="boxder">项目5</div>
  148. <div class="boxder">项目6</div>
  149. <div class="boxder">项目7</div>
  150. <div class="boxder">项目8</div>
  151. <div class="boxder">项目9</div>
  152. <div class="boxder">项目10</div>
  153. </div>
  154. </body>
  155. </html>
  156. flex简单实现让项目居中
  157. 怎么样很简单吧?几行代码搞定。不像之前的定位要设置很多参数,使用flex布局会更加的简洁方便!
  158. 代码块
  159. <!DOCTYPE html>
  160. <html lang="en">
  161. <head>
  162. <meta charset="UTF-8" />
  163. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  164. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  165. <title>flex简单实现让项目居中</title>
  166. <style type="text/css">
  167. * {
  168. box-sizing: border-box;
  169. }
  170. #box1 {
  171. border: 1px solid;
  172. width: 25em;
  173. height: 25em;
  174. background: lightpink;
  175. /* 设为flex容器 */
  176. display: flex;
  177. /* 让这个项目在水平线上居中 */
  178. justify-content: center;
  179. /* 让这个项目在交叉轴上居中 */
  180. align-items: center;
  181. }
  182. #box2 {
  183. border: 1px solid;
  184. width: 15em;
  185. height: 15em;
  186. background: limegreen;
  187. }
  188. </style>
  189. </head>
  190. <body>
  191. <div id="box1">
  192. <div id="box2"></div>
  193. </div>
  194. </body>
  195. </html>

更多相关文章

  1. 2017 github 上android 源码(适合工作中开发)
  2. 关于Android(安卓)Studio3.2新建项目Android(安卓)resource link
  3. Android平台上优秀的开源项目
  4. Android官方入门文档[1]创建一个Android项目
  5. GitHub 优秀的 Android(安卓)开源项目
  6. Ionic 运行报错No resource identifier found for attribute 'ap
  7. [APP] Android(安卓)开发笔记 006-使用短信验证SDK进行短信验证
  8. 【Android(安卓)应用开发】GitHub 优秀的 Android(安卓)开源项目
  9. android实践项目一实现简单的验证码和spinner下拉选项效果

随机推荐

  1. 从componentWillReceiveProps说起
  2. flexbox布局指南
  3. Mybaitis缓存的优化
  4. 分布式系统架构常见面试知识点梳理(每次面
  5. 图解源码 | SpringBoot中自动配置原理
  6. 单例模式你会几种写法?
  7. 一步为你的Springboot应用自定义banner
  8. 工厂模式理解了没有?
  9. 你的Springboot应用到底启动了哪些bean?这
  10. 单例模式的十种写法,你会几个?