html 伸缩布局,CSS3弹性伸缩布局(下)——flex布局

新版本

新版本的flex布局模型是2012年9月提出的工作草案,这个草案是由W3C推出的最新语法,这个版本立志于指定标准,让新式的浏览器全面兼容,在未来的浏览器更新换代中实现统一。

目前几乎大部分的浏览器都支持了。浏览器支持情况可以点击这里查看,下图为支持flex的情况

99304aeacc591a56063013950e50d814.png

//HTML代码部分

我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林

我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林

我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林我是吴广林

//CSS部分

p{

150px;

margin:5px;

padding: 5px;

border: 1px solid gray;

background: silver;

}

属性详解

首先和之前一样,先设置伸缩盒的display属性,有以下两个值

e15e6dac0d983e67d8886dafbabbbef6.png

div{

display: flex;

}

e8dbc74ee81249209407345a09c357f2.png

注意,设为Flex布局以后,子元素的float、clear和vertical-align属性将失效

接下来我们来测试flex布局的属性

1.flex-direction

//同旧版本的box-orient,设置伸缩项目的排列方式

047c8137f827feff36ed0e2124a26763.png

我们四个值都试试

flex-direction: row;

1d14415e49ee065361b69f47233b3853.png

flex-direction: row-reverse;

f8461b268fab564a85f1c9df6e2fdfd9.png

flex-direction: column;

ba598d9d6cbf232283988524ad6a438f.png

flex-direction: column-reverse;

90549a529d9447ab59659e54d5408dda.png

2.flex-wrap

//设置换行方式,类似旧版本的base-line,但是旧版本的base-line没有浏览器支持

b9ef6e6888de96946fd4bde647ebd8cc.png

flex-wrap: nowrap;

90f228476c345250b0e6a229773151f8.png

flex-wrap: wrap;

c34d036489c9953c0a59da403ec50692.png

flex-wrap: wrap-reverse;

e86b4af0a766ad4b7e63cdc4392f567a.png

3.flex-flow

//集合了flex-direction和flex-wrap的简写形式

flex-flow:row wrap;

20b46aa4698e540afc3bb3a8ab2b8ce4.png

4.justify-content

//同旧版本的box-pack,设置伸缩项目的对齐方式,或者说分布方式

aa7fe64296bff0ba3d2e55e33497d43d.png

每个值都试试吧

justify-content: flex-start;

9ddde5a688d5c9f1688c24126f6f81db.png

justify-content: flex-end;

cea5e2ecc47d18af53bc259d01db7361.png

justify-content: center;

67e194e9ae57c525b8a9cbe62e014d0c.png

justify-content: space-between;

278743c111c9eead8c2719a14c22ba08.png

justify-content: space-around;

0e3f6195fa2a659599f0676d53ac3891.png

5.align-items

//清理伸缩项目容器的额外空间,同旧版box-align

983747cd737a912ec40e3cd34a468c2e.png

还是一样,每个值都试下

align-items: flex-start;

8637a00f412ea64395c274c9014c414c.png

align-items: flex-end;

476f5c1d494f7af5a32c357e3e8dfdf5.png

align-items: center;

aa03f0c1b772f3e81d273c4b8892bed5.png

align-items: baseline;

7575a12c62add5af16b4f51479c7c7b7.png

align-items: stretch;

c254956ee0186bee6617a08b6df7cbb1.png

6.align-self

//align-self和align-item都是清理额外空间,但它是单独清理

p:nth-child(1){

align-self: center;

}

4a77dd7bf461d0425d9de8f4ea4401e2.png

7.flex

//同旧版box-flex,用于控制伸缩项目的比例分配

p:nth-child(1){

flex: 1;

}

p:nth-child(2){

flex: 2;

}

p:nth-child(3){

flex: 1;

}

7a171fc9c24272d822b722f57d86a100.png

8.order

//同旧版box-ordinal-group,控制伸缩项目出现的顺序

p:nth-child(1){

flex: 1;

order: 3;

}

p:nth-child(2){

flex: 2;

order: 1;

}

p:nth-child(3){

flex: 1;

order: 2;

}

ef82b5b5d1af8da9a3acaf1d68c43d4b.png

小结

如果觉得我讲的不好的话,也可以看看忨一峰的这篇Flex布局教程博客,希望能对你有所帮助。

好啦,三篇关于弹性布局的总算讲完拉,希望大家能好好运用flex布局,做出你的兼容式响应布局网页。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值