04-侧轴对齐方式.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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>侧轴对齐方式</title>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. }
  13. .box {
  14. display: flex;
  15. /* 居中 */
  16. /* align-items: center; */
  17. /* 拉伸,默认值(现有状态,测试的时候去掉子级的高度) */
  18. /* align-items: stretch; */
  19. height: 300px;
  20. margin: auto;
  21. border: 1px solid #000;
  22. }
  23. .box div {
  24. /* width: 100px; */
  25. /* height: 100px; */
  26. background-color: pink;
  27. }
  28. /* 单独设置某个弹性盒子的侧轴对齐方式 */
  29. .box div:nth-child(2) {
  30. align-self: center;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <div class="box">
  36. <div>1111</div>
  37. <div>2</div>
  38. <div>3</div>
  39. </div>
  40. </body>
  41. </html>