4_flex布局.html 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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: rgba(0,0,0,0.5);
  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. /* 占据剩余空间的一份 */
  23. flex: 1;
  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. <!--
  38. flex-direction 属性定义容器要在哪个方向上堆叠 flex 项目。
  39. row 默认值。作为一行,水平地显示弹性项目。
  40. row-reverse 等同行,但方向相反。
  41. column 作为列,垂直地显示弹性项目。
  42. column-reverse 等同列,但方向相反。
  43. flex-wrap 属性规定是否应该对 flex 项目换行。
  44. nowrap 默认值。规定弹性项目不会换行。
  45. wrap 规定弹性项目会在需要时换行。
  46. wrap-reverse 规定弹性项目会在需要时换行,以反方向。
  47. justify-content 属性用于对齐 flex 项目:
  48. flex-start 默认值。项目位于容器的开头。
  49. flex-end 项目位于容器的结尾。
  50. center 项目位于容器中央。
  51. space-between 项目在行与行之间留有间隔。
  52. space-around 项目在行之前、行之间和行之后留有空间。
  53. align-items 属性用于垂直对齐 flex 项目。
  54. stretch 默认。项目被拉伸以适合容器。
  55. center 项目位于容器的中央。
  56. flex-start 项目位于容器的开头。
  57. flex-end 项目位于容器的末端。
  58. baseline 项目被定位到容器的基线。
  59. align-content 属性用于对齐弹性线。
  60. stretch 默认值。行拉伸以占据剩余空间。
  61. center 朝着弹性容器的中央对行打包。
  62. flex-start 朝着弹性容器的开头对行打包。
  63. flex-end 朝着弹性容器的结尾对行打包。
  64. space-between 行均匀分布在弹性容器中。
  65. space-around 行均匀分布在弹性容器中,两端各占一半。
  66. -->
  67. </div>
  68. </body>
  69. </html>