博客列表 >flex容器常用的四个属性

flex容器常用的四个属性

酿酒的人ァ
酿酒的人ァ原创
2021年03月27日 08:38:08522浏览
  • flex-flow: 设置主轴的方向和项目在主轴的换行方式
  • justify-content: 项目在主轴的对齐方式
  • align-items: 项目在交叉轴上的对齐方式
  • align-content: 设置项目在多行容器中的对齐方式

代码实例:

  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>实例演示:flex容器常用的四个属性</title>
  7. <style>
  8. * {
  9. box-sizing: border-box;
  10. }
  11. .container {
  12. height: 15em;
  13. border: 1px solid coral;
  14. padding: 1em;
  15. margin: 1em;
  16. display: flex;
  17. }
  18. .container > .item {
  19. width: 8em;
  20. background-color: lightyellow;
  21. border: 1px solid chocolate;
  22. }
  23. .container {
  24. flex-flow: row nowrap;
  25. flex-flow: row wrap;
  26. }
  27. /* .container {
  28. flex-flow: column nowrap;
  29. flex-flow: column wrap;
  30. flex-flow: column wrap-reverse;
  31. height: 8em;
  32. } */
  33. .container {
  34. justify-content: flex-start;
  35. justify-content: flex-end;
  36. justify-content: flex-end;
  37. justify-content: center;
  38. justify-content: space-between;
  39. justify-content: space-around;
  40. justify-content: space-evenly;
  41. }
  42. .container {
  43. flex-flow: row nowrap;
  44. align-items: stretch;
  45. align-items: flex-start;
  46. align-items: flex-end;
  47. align-items: center;
  48. }
  49. /.container {
  50. flex-flow: row wrap;
  51. align-content: stretch;
  52. align-content: flex-end;
  53. align-content: flex-start;
  54. align-content: center;
  55. align-content: space-around;
  56. align-content: space-between;
  57. align-content: space-evenly;
  58. }
  59. </style>
  60. </head>
  61. <body>
  62. <div class="container">
  63. <div class="item">item1</div>
  64. <div class="item">item2</div>
  65. <div class="item">item3</div>
  66. <div class="item">item4</div>
  67. <div class="item">item5</div>
  68. <div class="item">item6</div>
  69. <div class="item">item7</div>
  70. <div class="item">item8</div>
  71. </div>
  72. </body>
  73. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议