Blogger Information
Blog 12
fans 0
comment 0
visits 11062
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
FlexBox弹性盒子布局属性(二)
amin
Original
652 people have browsed it

FlexBox弹性盒子布局之子元素属性

1、order : 定义项目的排列顺序,数值越小排列越靠前,默认为0

效果图

.container > .item:first-of-type {order: 3;}

2、flex-grow : 定义项目的放大比例,默认为0(如果存在剩余空间也不放大)。如果所有项目的flex-grow属性都为1,则他们将等分剩余空间,若各项目的flex-grow的值不相同,则按比例分配剩余空间。
  1. css代码
  2. .container {
  3. width: 300px;
  4. display: flex;
  5. padding: 5px 0;
  6. background: #9C27B0;
  7. }
  8. .container > .item {
  9. background: #7FFFD4;
  10. border: 1px solid #000;
  11. width: 40px;
  12. flex: auto;
  13. }
  14. .container > .item:first-of-type {
  15. flex-grow: 1;
  16. }
  17. .container > .item:nth-of-type(2){
  18. flex-grow: 2;
  19. }
  20. .container > .item:last-of-type{
  21. flex-grow: 3;
  22. }
  23. html代码
  24. <div class="container">
  25. <div class="item">1</div>
  26. <div class="item">2</div>
  27. <div class="item">3</div>
  28. </div>

效果图

3、flex-shrink : 定义了项目的缩小比例,默认值为1(如果空间不足该项目将等比例缩小)。如果一个项目的flex-shrink属性为0,其他项目都为1,则空间不足时,前者不缩小。空间不足时,如果各项目的flex-shrink的值不相同,则按比例缩小。
  1. css代码
  2. .container {
  3. width: 300px;
  4. display: flex;
  5. padding: 5px 0;
  6. background: #9C27B0;
  7. }
  8. .container > .item {
  9. background: #7FFFD4;
  10. border: 1px solid #000;
  11. width: 200px;
  12. flex: auto;
  13. }
  14. .container > .item:first-of-type {
  15. flex-shrink: 1;
  16. }
  17. .container > .item:nth-of-type(2){
  18. flex-shrink: 2;
  19. }
  20. .container > .item:last-of-type{
  21. flex-shrink: 3;
  22. }
  23. html代码
  24. <div class="container">
  25. <div class="item">1</div>
  26. <div class="item">2</div>
  27. <div class="item">3</div>
  28. </div>

效果图

4、flex-basis : 定义了项目在主轴有剩余空间的时候,分配项目占据的主轴空间,优先级 width < flex-basis < min-width
5、flex : flex-growflex-shrinkflex-basis的简写,默认值为0 1 auto。后两个属性为非必选项。
6、align-self : 该属性允许单个项目与其他项目不一样的侧轴对齐方式
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:这些都是理论知识 , 后面我们还有大量的实战要用到它们的
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post