7_flex.html 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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{
  9. width: 100%;
  10. /* height: 600px; */
  11. border:2px dashed black;
  12. padding:20px;
  13. box-sizing: border-box;
  14. /* flex 弹性盒子 flex布局 内部元素默认为横向排列(主轴依次排列)*/
  15. /* flex 有两个轴 主轴(默认情况下横向) 交叉轴(默认为纵向) */
  16. display: flex;
  17. /* flex-direction 改变flex 主轴的方向 column改为纵向 */
  18. /* flex-direction: column; */
  19. /* flex-direction: row-reverse; */
  20. /* flex-direction: column-reverse; */
  21. /* justify-content 控制flex元素在主轴上的排列方式 space-between两端对齐 space-around分散对齐 flex-start主轴的开始位置依次排列 flex-end在结束位置依次排列 center居中展示*/
  22. /* justify-content: center; */
  23. /* align-items 控制flex元素在交叉轴上的排列方式 */
  24. /* align-items: center; */
  25. /* flex中如果内部元素所在行容纳不下所有元素那么会对内部flex元素进行压缩 */
  26. /* flex-wrap 控制flex元素是否换行展示 默认为nowrap不换行 wrap换航*/
  27. /* flex-wrap: wrap; */
  28. /* align-content 当flex元素换行后产生多个轴的时候布局方式 属性值等同于 justify-content*/
  29. /* align-content: space-between; */
  30. }
  31. .box .box1{
  32. width: 200px;
  33. height: 200px;
  34. background-color: blue;
  35. color: white;
  36. font-size: 50px;
  37. text-align: center;
  38. line-height: 200px;
  39. font-weight: bold;
  40. margin-left: 5px;
  41. margin-top: 5px;
  42. /* float: left; */
  43. /* flex-grow 放大flex元素 后边的值表示放大比例 相当于把所在空间的剩余位置按照比例划分 */
  44. /* flex-grow: 1; */
  45. /* flex-shrink: 1; */
  46. }
  47. .box1:nth-child(3){
  48. /* flex-grow: 4; */
  49. }
  50. .box1:nth-child(4){
  51. /* flex-grow: 1; */
  52. /* flex:1; */
  53. }
  54. .box1:nth-child(6){
  55. /* flex-shrink 缩小比例 如果元素一行容纳不下flex元素会相应缩小默认都是等比例 也可以flex-shrink设置某一个元素的缩小比例*/
  56. /* flex-shrink: 2; */
  57. }
  58. .box1:nth-child(5){
  59. /* align-self 可以单独设置某一个flex元素的对齐方式 flex-end flex-start center */
  60. /* align-self: flex-end; */
  61. }
  62. .box1:nth-child(8){
  63. /*order 可以控制flex元素的排列顺序 值越小越靠前越大越靠后 */
  64. /* order: -1; */
  65. }
  66. </style>
  67. </head>
  68. <body>
  69. <div class="box">
  70. <div class="box1">1</div>
  71. <div class="box1">2</div>
  72. <div class="box1">3</div>
  73. <div class="box1">4</div>
  74. <div class="box1">5</div>
  75. <!-- <div class="box1">6</div>
  76. <div class="box1">7</div>
  77. <div class="box1">8</div>
  78. <div class="box1">9</div>
  79. <div class="box1">10</div>
  80. <div class="box1">11</div> -->
  81. </div>
  82. </body>
  83. </html>