justify-content:flex-start 默认值从头部开始 如果主轴是x轴,则从左到右;

1.justify-content:flex-end 从尾部开始排列

image.png

  1. .box{
  2. width: 200px;
  3. height: 200px;
  4. border: 1px solid red;
  5. margin: 100px auto;
  6. display: flex;
  7. flex-direction:row;
  8. justify-content: flex-end;
  9. }
  10. .box span{
  11. display: inline-block;
  12. width: 30px;
  13. height: 30px;
  14. background-color: pink;
  15. border-radius: 50%;
  16. }
  17. <div class="box">
  18. <span>1</span>
  19. <span>2</span>
  20. <span>3</span>
  21. </div>

2.justify-content:center 在主轴居中对齐

image.png

  1. .box{
  2. width: 200px;
  3. height: 200px;
  4. border: 1px solid red;
  5. margin: 100px auto;
  6. display: flex;
  7. flex-direction:row;
  8. justify-content: center;
  9. }
  10. .box span{
  11. display: inline-block;
  12. width: 30px;
  13. height: 30px;
  14. background-color: pink;
  15. border-radius: 50%;
  16. }

3.space-around: 子元素跟子元素间隙大两倍

image.png

  1. .box{
  2. width: 200px;
  3. height: 200px;
  4. border: 1px solid red;
  5. margin: 100px auto;
  6. display: flex;
  7. flex-direction:row;
  8. justify-content: space-around;
  9. }
  10. .box span{
  11. display: inline-block;
  12. width: 30px;
  13. height: 30px;
  14. background-color: pink;
  15. border-radius: 50%;
  16. }

4.space-between:先两边贴边 在平分剩余空间(重要)—>

image.png

  1. .box{
  2. width: 200px;
  3. height: 200px;
  4. border: 1px solid red;
  5. margin: 100px auto;
  6. display: flex;
  7. flex-direction:row;
  8. justify-content: space-between;
  9. }
  10. .box span{
  11. display: inline-block;
  12. width: 30px;
  13. height: 30px;
  14. background-color: pink;
  15. border-radius: 50%;
  16. }