jiaochunxiao / fe-blog

好好学习,天天向上
1 stars 1 forks source link

flex: 1,对应的具体的值 #14

Open jiaochunxiao opened 4 years ago

jiaochunxiao commented 4 years ago

flex相关

容器属性

flex-direction、flex-wrap、flex-flow、justify-content、align-items、align-content

.box {
  flex-direction: row | row-reverse | column |column-reverse;
}

项目属性

order、 flex-grow 、 flex-shrink、 flex-basis、flex、algin-self

复习完基本的知识,现在来看 flex: 1。

flex : 1

flex为一个非负数字n:该数字为flex-grow的值,

 flex:n;
 =
 flex-grow:n;
 flex-shrink: 1;
 flex-basis:0%;

flex为两个非负数字n1,n2: 分别为flex-grow和flex-shrink的值,

  flex:n1 n2; 
  =
  flex-grow:n1;
  flex-shrink:n2;
  flex-basis:0%;

flex为一个长度或百分比L:视为flex-basis的值,

  flex: L; 
  = 
  flex-grow:1;
  flex-shrink:1;
  flex-basis:L;

flex为一个非负数字n和一个长度或百分比L:分别为flex-grow和flex-basis的值,

  flex:n L
  =
  flex-grow:n;
  flex-shrink:1;
  flex-basis:L;

可以发现,flex-grow和flex-shrink在flex属性中不规定值则为1,flex-basis为0%。 flex:1即为flex-grow:1,经常用作自适应布局,将父容器的display:flex,侧边栏大小固定后,将内容区flex:1,内容区则会自动放大占满剩余空间。

参考

jiangzhenxiang commented 4 years ago

flex: 1flex-grow: 1; flex-shrink: 1; flex-basis: auto

flex: 1,这个1表示flex-grow,此时flex-shrinkflex-basis都使用默认值,分别是1auto

jiaochunxiao commented 4 years ago

flex: 1flex-grow: 1; flex-shrink: 1; flex-basis: auto

flex: 1,这个1表示flex-grow,此时flex-shrinkflex-basis都使用默认值,分别是1auto

当flex取值为一个非负数字时,则该数字是设置的flex-grow值,其它两个属性用初始值,如flex:1时,等同于flex: 1 1 0%