5.弹性盒容器属性.css 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #box {
  2. /* width: 900px; */
  3. width: 550px;
  4. height: 300px;
  5. background: #ccc;
  6. display: flex;
  7. flex-wrap: wrap;
  8. align-content:stretch;
  9. /* flex-direction: column; */
  10. /* align-items: center; */
  11. /* justify-content:space-evenly; */
  12. /* flex-direction:column-reverse; */
  13. /* display: inline-flex; */
  14. }
  15. #box4 {
  16. width: 100px;
  17. height: 50px;
  18. background: #f00;
  19. }
  20. #box5 {
  21. width: 120px;
  22. height: 100px;
  23. background: #ff0;
  24. }
  25. #box6 {
  26. width: 100px;
  27. height: 100px;
  28. background: #00f;
  29. }
  30. /* #box1 {
  31. width: 200px;
  32. height: 100px;
  33. background: #f00;
  34. }
  35. #box2 {
  36. width: 200px;
  37. height: 100px;
  38. background: #ff0;
  39. }
  40. #box3 {
  41. width: 200px;
  42. height: 100px;
  43. background: #00f;
  44. } */
  45. .new {
  46. width: 400px;
  47. display: flex;
  48. flex-flow: row wrap-reverse;
  49. /* flex-wrap:wrap-reverse; */
  50. }
  51. .new1,.new2,.new3 {
  52. width: 100px;
  53. height: 100px;
  54. }
  55. .new1 {
  56. background: #00f;
  57. }
  58. .new2 {
  59. background: #f00;
  60. }
  61. .new3 {
  62. background: #ff0;
  63. }
  64. /*
  65. 弹性盒:容器属性、项目属性
  66. 容器属性:
  67. 开启弹性盒:display:flex;(常用)
  68. display:inline-flex;(开启弹性盒子 以内联形式展示)
  69. display:-moz-flex;
  70. 注意:设置为flex布局后,子元素的float、clear属性将失效;
  71. 1.flex-direction:控制弹性盒子方向
  72. row(默认) 从左到右
  73. row-reverse 从右到左
  74. column 从上到下
  75. column-reverse 从下到上
  76. 2.flex-wrap:控制弹性盒子换行
  77. nowrap 不换行(默认)
  78. wrap 换行
  79. wrap-reverse 换行 第一行在下面
  80. 3.flex-flow(排列):flex-direction flex-wrap
  81. flex-flow:row nowrap;
  82. 4.justify-content:水平对齐方式
  83. flex-start 左对齐 (默认)
  84. flex-end 右对齐
  85. center 居中
  86. space-around:项目均匀分布,每一个项目两侧有相同的留白空间,相邻项目之间的距 离是两个项目之间留白的和
  87. space-between:两端对齐,项目之间间隔相等
  88. space-evenly:项目均匀分布,所有项目之间及项目与边框之间距离相等;
  89. 5.align-items:交叉轴对齐方式
  90. stretch(默认值):如果项目未设置高度或设为auto,将占满整个容器的高度。
  91. flex-start:交叉轴的起点对齐。
  92. flex-end:交叉轴的终点对齐。
  93. center:交叉轴的中点对齐。
  94. baseline: 项目的第一行文字的基线对齐。
  95. 6.align-content:轴线的对齐方式(一根轴不生效)
  96. stretch (默认):拉伸显示
  97. flex-start:从启点线开始顺序排列
  98. flex-end:相对终点线顺序排列
  99. center:居中排列
  100. space-between:项目均匀分布,第一项在启点线,最后一项在终点线
  101. space-around:项目均匀分布,每一个项目两侧有相同的留白空间,相邻项目之间的距离是两个项目之间留白的和
  102. 注意: Internet Explorer 10 及更早版本浏览器不支持 align-content 属性。
  103. 注意: Safari 7.0 及更新版本通过 -webkit-align-content 属性支持该属性。
  104. 注意:Internet Explorer, Firefox, 和 Safari 浏览器不支持 align-content 属性。
  105. */