浅谈flex布局

Flex布局,俗称弹性布局,有了这个布局,我们作的事情不少,之前那些很难实现好比说垂直居中之类都不存在了。css

盒模型布局依赖于float,display,定位之类的方式来布局,这种的布局对一些特殊布局来讲很不方便,就如上面的垂直居中就不太好实现。布局

如今就让我来介绍一个Flex布局方式flex

他中的一些属性:spa

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

在这里,声明一点,使用了display:flex;布局,其子元素内的floatclearvertical-align属性将失效code

flex-direction属性

.box { flex-direction: row | row-reverse | column | column-reverse; }
  • row(默认值):主轴为水平方向,起点在左端。
  • row-reverse:主轴为水平方向,起点在右端。
  • column:主轴为垂直方向,起点在上沿。
  • column-reverse:主轴为垂直方向,起点在下沿。

flex-wrap属性

.box{ flex-wrap: nowrap | wrap | wrap-reverse; }

(1)nowrap(默认):不换行。token

 

(2)wrap:换行,第一行在上方。it

 

(3)wrap-reverse:换行,第一行在下方。io

 

flex-flow属性



属性是属性和属性的简写形式,默认值为。

.box { flex-flow: <flex-direction> || <flex-wrap>; }flex-flowflex-directionflex-wraprow nowrap

 justify-content属性


.box { justify-content: flex-start | flex-end | center | space-between | space-around; }
  • flex-start(默认值):左对齐
  • flex-end:右对齐
  • center: 居中
  • space-between:两端对齐,项目之间的间隔都相等。
  • space-around:每一个项目两侧的间隔相等。因此,项目之间的间隔比项目与边框的间隔大一倍。

align-items属性

align-items属性定义项目在交叉轴上如何对齐class

.box { align-items: flex-start | flex-end | center | baseline | stretch; }
  • flex-start:交叉轴的起点对齐。
  • flex-end:交叉轴的终点对齐。
  • center:交叉轴的中点对齐。
  • baseline: 项目的第一行文字的基线对齐。
  • stretch(默认值):若是项目未设置高度或设为auto,将占满整个容器的高度。

 

align-content属性

 



.box { align-content: flex-start | flex-end | center | space-between | space-around | stretch; }
  • flex-start:与交叉轴的起点对齐。
  • flex-end:与交叉轴的终点对齐。
  • center:与交叉轴的中点对齐。
  • space-between:与交叉轴两端对齐,轴线之间的间隔平均分布。
  • space-around:每根轴线两侧的间隔都相等。因此,轴线之间的间隔比轴线与边框的间隔大一倍。
  • stretch(默认值):轴线占满整个交叉轴。
相关文章
相关标签/搜索