首先要有个容器,并设置display:flex;display:-webkit-flex;该容器有以下六个属性:

1
2
3
4
5
6
7
8
9
10
11
12
flex-direction (元素排列方向)
    row, row-reverse, column, column-reverse
flex-wrap (换行)
    nowrap, wrap, wrap-reverse
flex-flow (以上两者的简写)
    flex-direction || flex-wrap
justify-content (水平对齐方式)
    flex-start, flex-end, center, space-between, space-around
align-items (垂直对齐方式)
    stretch, flex-start, flex-end, center, baseline
align-content (多行垂直对齐方式)
    stretch, flex-start, flex-end, center, space-between, space-around

项目的属性:

1
2
3
4
5
6
7
8
9
10
11
order 排列顺序,数值,默认0
    "integer"
flex-grow 如图示7,定义放大比例,默认0,即如果存在剩余空间,也不放大。
    "number"
flex-shrink 如图示8,定义缩小比例,默认1,如果所有项目的flex-shrink属性都为1,当空间不足时,都将等比例缩小。如果一个项目的flex-shrink属性为0,其他项目都为1,则空间不足时,前者不缩小。
    "number"
flex-basis 定义项目占据的主轴空间,默认auto。会根据flex-direction定义的主轴(水平或者垂直),定义项目本来的大小,跟width或者height一样。
flex 推荐,以上三个的缩写,默认 0 1 auto
    "flex-grow" "flex-shrink" "flex-basis"
align-self 如图示9,单个项目有与其他项目不一样的对齐方式,可覆盖align-items
    "auto","flex-start","flex-end","center","baseline","stretch" 

1.flex-direction

1
2
3
4
row (从左往右)默认
row-reverse (从右往左)
column (从上往下)
column-reverse (从下往上)

2.flex-wrap

1
2
3
nowrap (不换行)默认
wrap (换行,且往下一行换)
wrap-reverse (换行,且往上一行换)

3.flex-flow,是flex-direction和flex-wrap的简写形式。

1
flex-flow:<flex-direction> || <flex-wrap>;

4.justify-content

1
2
3
4
5
flex-start
flex-end
center
space-between
space-around

5.align-items

1
2
3
4
5
stretch 默认
flex-start
flex-end
center
baseline 项目第一行文字的基准线对齐

  

6.align-content

1
2
3
4
5
6
stretch 默认
flex-start
flex-end
center
space-between
space-around

7.flex-grow

定义了放大比例,默认为0,即如果存在剩余空间,也不会放大。但是,如果所有项目的flex-grow属性为1,则他们将等分剩余空间(如果有的话),如果其中一个为2,则他是其他项目的2倍宽度。

8.flex-shrink

定义了项目的缩小比例,默认为1,即如果空间不足,项目将缩小。如果有一个项目的flex-shrink为0,其他都为1,空间不足时,前者不缩小。

9.align-self,定义项目自己的对齐方式

3分钟看懂flex布局的更多相关文章

  1. 30分钟彻底弄懂flex布局

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由elson发表于云+社区专栏 目前在不考虑IE以及低端安卓机(4.3-)的兼容下,已经可以放心使用flex进行布局了.什么是flex布 ...

  2. 弄懂flex布局

    目前在不考虑IE以及低端安卓机(4.3-)的兼容下,已经可以放心使用flex进行布局了.什么是flex布局以及它的好处,这里就不再赘述. 在这篇文章里,想说说flex布局的属性语法及其细节.那么网上也 ...

  3. [转帖]10分钟看懂Docker和K8S

    10分钟看懂Docker和K8S https://zhuanlan.zhihu.com/p/53260098 2010年,几个搞IT的年轻人,在美国旧金山成立了一家名叫“dotCloud”的公司. 这 ...

  4. 十分钟看懂AES加密

    十分钟看懂AES加密算法 今天看了Moserware的<A Stick Figure Guide to the Advanced Encryption Standard(AES)>收获了不 ...

  5. 一篇文章弄懂flex布局

     壹 ❀ 引 谈到flex布局,我不知道有多少人跟我一样,在本能的想到justify-content:center与align-items:center两条属性之后,除此之外的其它属性居然显得格外陌生 ...

  6. 5分钟看懂Code128条形码

    什么是Code128条形码? 相信大家看到这个都不陌生吧 1.前言 条形码种类很多,常见的大概有二十多种码制,其中包括:Code39码(标准39码).Codabar码(库德巴码).Code25码(标准 ...

  7. 微信小程序开发之搞懂flex布局1——Flexbox

    Flexbox ——弹性布局 Flexbox is a layout model for displaying items in a single dimension — as a row or as ...

  8. 10分钟看懂Docker和K8S

    本文来源:鲜枣课堂 2010年,几个搞IT的年轻人,在美国旧金山成立了一家名叫"dotCloud"的公司. 这家公司主要提供基于PaaS的云计算技术服务.具体来说,是和LXC有关的 ...

  9. 十分钟看懂,未来Web前端开发最新趋势

    首先,展望未来趋势我们就要弄懂过去的一年,也就是18年,web前端开发的重要新闻.重要事件和JavaScript的各种流行框架.模式发展趋势. 我们来快速回顾一下. NPM热门前端框架下载 先来看最热 ...

随机推荐

  1. js cookies all in one

    js cookies all in one cookies // http://10.1.5.202/auto-deploy-platform/publish/index.html // 非当前 UR ...

  2. 为 Windows Phone 8.1 app 解决“The type does not support direct content.”的问题

    我在 VS 14 CTP 中新建了一个空的 app store 项目名叫 PlayWithXaml ,项目的 MainPage.xaml 文件改为了以下内容: <Page x:Class=&qu ...

  3. Keywords Search AC自动机

    In the modern time, Search engine came into the life of everybody like Google, Baidu, etc. Wiskey al ...

  4. ACM 数学

    欧几里得辗转相除法求最大公约数 int gcd(int a,int b) { ) return a; else return gcd(b,a%b); } 求组合数 int C(int n ,int m ...

  5. UVA_1575

    https://vjudge.net/problem/UVA-1575 枚举答案(k)..对k质因数分解,质数的指数为cnt[i],若n==A(tot_cnt,tot_cnt) / A(cnt[i]& ...

  6. cogs——1578. 次小生成树初级练习题

    1578. 次小生成树初级练习题 ☆   输入文件:mst2.in   输出文件:mst2.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 求严格次小生成树 [输入格式 ...

  7. Oracle Multitenant Environment (一) About

    About oracle mulittenant environment The multitenant architecture enables an Oracle database to func ...

  8. mybatis指定jdbctype

    MyBatis 插入空值时,需要指定JdbcType mybatis insert空值报空值异常,但是在pl/sql不会提示错误,主要原因是mybatis无法进行转换 所以在MyBatis映射文件中要 ...

  9. Username is not in the sudoers file. This incident will be reported

    type sudo adduser <username> sudo where username is the name of the user you want to add in th ...

  10. java学习总结——你的前世今生

    一.背景 JAVA语言最開始仅仅是Sun电脑(Sun MicroSystems)公司在1990年12月開始研究的一个内部项目. Sun电脑公司的一个叫做帕特里克·诺顿的project师被公司自己开发的 ...