Personally, I think that compared to using float layout (floating layout is generally suitable for text wrapping), elastic layout will be more convenient, concise and powerful (this is a long article, the front is the value and attribute table, and the back is the rendering of each attribute )
1. Attributes and their values
Attributes |
description and value |
display |
Specifies the HTML element box type:
|
flex-direction |
Specifies the arrangement of child elements in the flex container :
|
justify-content |
Set the alignment of flexbox elements in the direction of the main axis (horizontal arrangement is the x-axis, vertical arrangement is the y-axis):
|
align-items |
Sets the alignment of flexbox elements in the direction of the cross (vertical) axis:
|
flex-wrap |
Set whether to wrap when the child elements of the flexbox exceed the parent container:
|
flex-flow |
|
align-content: |
If there is only one axis, then this property will not work , that is, there must be multiple lines of items in the container for this property to have an effect: (the general position is related to the value of flex-directio )
|
order |
设置弹性盒子的子元素排列顺序。(Internet Explorer 和 Safari 不支持 order 属性) |
align-self |
覆盖容器的 align-items 属性也就是重写了容器的 align-items 属性(允许单个项目有与其他项目不一样的对齐方式) |
flex |
设置弹性盒子的子元素如何分配空间。 |
flex-basis |
规定弹性项目的初始长度 |
flex-shrink |
flex-shrink属性定义了项目的缩小比例,默认为1,即如果空间不足,该项目将缩小。 |
flex-grow |
定义项目的放大比例,默认为0,即如果存在剩余空间,也不放大 |
注:设为Flex布局以后,子元素的float、clear和vertical-align等属性都将失效。
1.flex-direction
2.justify-content(展示的是水平排列,基于x轴的;纵向排列则基于y轴此属性一般用于水平布局)
3.align-items(展示的是垂直排列,基于y轴的;纵向排列则基于x轴此属性一般用于垂直布局)
4.flex-wrap (展示的是水平布局的flex-wrap,可更改flex-direction来修改方向 )
5.flex-flow(是是flex-direction属性和flex-wrap属性的简写、默认值为row nowrap)
6. align-content(容器内必须要有多行的项目,该属性才能有效果效果:(一般位置与flex-directio的值相关因为其他值与justify-content、align-items类似,这里只展示了stretch)
7.order(Internet Explorer 和 Safari 不支持 此 属性。)
8.align-self(重写了容器的 align-items 属性)
9.flex(弹性盒子如何分配父容器空间(1/2/3/4...等),全体flex:1;平均分配,水平时父容器内有的盒子设置了宽,给一个盒子设置flex:1;则占满剩下的全部空间(宽))
10.flex-basis:规定弹性项目的初始长度