4_弹性盒模型.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #div1 {
  10. height: 500px;
  11. background: black;
  12. display: flex;
  13. }
  14. #div2 {
  15. width: 200px;
  16. height: 200px;
  17. background: red;
  18. }
  19. #div3 {
  20. height: 200px;
  21. background: blue;
  22. flex: 1;
  23. /* 占据剩余空间的一份 */
  24. }
  25. #div4 {
  26. height: 200px;
  27. background: orange;
  28. flex: 2;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="div1">
  34. <div id="div2"></div>
  35. <div id="div3"></div>
  36. <div id="div4"></div>
  37. </div>
  38. <!--
  39. display: flex 父元素设置
  40. flex-direction 决定主轴的方向
  41. row(默认值): 主轴是水平方向,起点在左侧
  42. row-reverse: 主轴是水平方向,起点在右侧
  43. column: 主轴为垂直方向,起点在上方
  44. column-reverse: 主轴是垂直方向,起点在下方
  45. flex-wrap 是否应该对 flex 项目换行
  46. nowrap(默认值) 规定将不对 flex 项目换行
  47. wrap 换行,第一行在上方
  48. wrap-reverse 换行,第一行在下方
  49. justify-content 对齐 flex 项目
  50. flex-start: 左对齐(默认值)
  51. flex-end: 右对齐
  52. center: 居中
  53. space-between: 两端对齐,项目之间的间隔相等
  54. space-around: 每个项目环绕的距离相等
  55. align-items 用于垂直对齐 flex 项目
  56. flex-start: 上对齐
  57. flex-end: 下对齐
  58. center: 居中
  59. stretch 值拉伸 flex 项目以填充容器(默认)
  60. baseline 值使 flex 项目基线对齐
  61. align-content 属性用于对齐弹性线
  62. space-between 值显示的弹性线之间有相等的间距
  63. stretch 值拉伸弹性线以占据剩余空间(默认)
  64. center 值在容器中间显示弹性线
  65. flex-start 值在容器开头显示弹性线
  66. flex-end 值在容器的末尾显示弹性线
  67. -->
  68. </body>
  69. </html>