8_flex.html 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. .box div{
  9. width: 200px;
  10. height: 200px;
  11. background-color: red;
  12. margin:10px;
  13. font-size: 50px;
  14. font-weight: bold;
  15. color: white;
  16. text-align: center;
  17. line-height: 200px;
  18. }
  19. .box{
  20. height: 700px;
  21. background-color: blue;
  22. /* display: flex; 把当前容器设置成弹性盒子(flex布局) */
  23. /* 默认情况下会将内部所有元素在主轴上横向排列 (主轴方向默认横向) */
  24. display: flex;
  25. /* 调整主轴方向 row 横向 column 纵向 */
  26. /* flex-direction: column; */
  27. /* row-reverse 横向反转 column-reverse 纵向反转 */
  28. /* flex-direction: row-reverse; */
  29. /* flex-wrap: wrap 换行 */
  30. /* flex布局默认情况 元素不换行 如果一行装不下会压缩元素 */
  31. /* flex-wrap: wrap; */
  32. /* justify-content 主轴对齐方式 flex-start flex-end center */
  33. /* space-between 两端对齐 space-around 分散对齐 */
  34. /* justify-content: space-around; */
  35. /* justify-content: space-between; */
  36. /* justify-content: center; */
  37. /* 交叉轴排列方式 flex-start flex-end center */
  38. /* align-items: stretch; */
  39. /* aligin-content 控制多行对齐 */
  40. /* align-content: space-between; */
  41. }
  42. /* 用于每一个子项上的属性 */
  43. /* order 子项的排序 值越小越靠前 值越大越靠后*/
  44. /* .box div:nth-child(3){
  45. order: -1;
  46. }
  47. .box div:first-child{
  48. order: 10;
  49. } */
  50. /* flex-grow 子项的放大比例 */
  51. /* flex-grow 会把剩余空间进行分配 子项 flex-grow 比例分配 */
  52. /* .box div:nth-child(4){
  53. flex-grow: 2;
  54. }
  55. .box div:nth-child(3){
  56. flex-grow: 1;
  57. } */
  58. /* flex-shrink 子项的缩小比例 */
  59. /* flex-shrink 会把超出空间进行压缩 子项 flex-shrink 比例压缩 */
  60. /* .box div:nth-child(3){
  61. flex-shrink: 0;
  62. } */
  63. .box div{
  64. /* flex:0 0 200px; */
  65. }
  66. .box div:nth-child(2){
  67. align-self: flex-end;
  68. }
  69. </style>
  70. </head>
  71. <body>
  72. <div class="box">
  73. <div>1</div>
  74. <div>2</div>
  75. <div>3</div>
  76. <!-- <div>4</div>
  77. <div>5</div>
  78. <div>6</div>
  79. <div>7</div>
  80. <div>8</div> -->
  81. </div>
  82. </body>
  83. </html>