Flex布局

1、Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。


flex布局

.container { display: flex; /* or inline-flex */ }

Flex六个属性
flex-direction
flex-wrap
flex-flow
justify-content
align-items
align-content

2、flex-direction属性

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

3、flex-wrap属性

flex-wrap属性
.container{ flex-wrap: nowrap | wrap | wrap-reverse; } 
nowrap(默认):不换行。
wrap:换行,第一行在上方。
wrap-reverse:换行,第一行在下方。

4、flex-flow 属性(是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap)

flex-flow: <‘flex-direction’> || <‘flex-wrap’>

5、justify-content属性

justify-content属性
.container { justify-content: flex-start | flex-end | center 
                 | space-between | space-around | space-evenly; } 
flex-start(默认值):左对齐 
flex-end:右对齐 
center: 居中 
space-between:两端对齐,项目之间的间隔都相等。 
space-around:每个项目两侧的间隔相等。项目之间的间隔比项目与边框的间隔大一倍。 
space-evenly:物品的分布使得任何两个物品之间的间距(以及到边缘的空间)相等。 
space-evenly在微信PC端和IE浏览器打开会有失效。

6、align-items属性

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

7、align-content属性

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

8、order属性定义项目的排列顺序。数值越小,排列越靠前,默认为0。

order属性

.item { order: <integer>; /* default is 0 */ }

9、flex-grow属性定义项目的放大比例,默认为0,即如果存在剩余空间,也不放大。

flex-grow属性

.item { flex-grow: <number>; /* default 0 */ }

10、flex-shrink

.item { flex-shrink: <number>; /* default 1 */ }

11、flex-basis

.item { flex-basis: <length> | auto; /* default auto */ }

12、flex

.item { flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ] }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。