赞
踩
以下文章主要探讨 HTML5 中 CSS3 提供的用来实现未来响应式弹性伸缩布局方案。
一、flex布局的语法
块级元素 :display: flex ———— 将容器盒模型作为块级弹性伸缩盒显示
行内元素 :display: inline-flex ———— 将容器盒模型作为内联级弹性伸缩盒显示
设置flex布局后,flex item的float、clear和vertical-align 属性都失效
flex布局默认为横向
css
- <style>
- .flex-box{
- width: 1000px;
- height: 500px;
- margin: 0 auto;
- border: solid 1px red;
- display: flex;
- }
- .flex{
- width: 150px;
- height: 150px;
- background: blue;
- border: solid 1px rgb(255, 208, 0);
- }
- </style>
html
- <div class="flex-box">
- <div class="flex">第一个div</div>
- <div class="flex">第二个div</div>
- <div class="flex">第三个div</div>
- <div class="flex">第四个div</div>
- </div>
加了"display:flex;"布局默认为横向
二、容器属性
元素名称 | 说明 |
flex-direction:column | 设置从上往下排列 |
flex-direction:column-reverse | 设置从下到上排列 |
flex-direction:row | 设置从左到右排列 |
flex-direction:row-reverse | 设置从右到左排列 |
1,加了"display:flex;flex-direction:column;"布局从上往下排列
2,加了"display:flex;flex-direction:column-reverse;"布局从上往下排列
3,加了"display:flex;flex-direction:row;"布局从左到右排列
4,加了"display:flex;flex-direction:row-reverse;"设置从右到左排列
没有设置子级flex为1时:flex-wrap
没有设置高度时会均分父级
元素名称 | 说明 |
flex-wrap:nowrap | 默认值,都在一行或一列显示 |
flex-wrap:wrap | 伸缩项目无法容纳时,自动换行 |
flex-wrap:wrap-reverse | 伸缩项目无法容纳时,自动换行,方向和 wrap 相反 |
1,当 flex-wrap: nowrap 时 ———— 默认值,都在一行或一列显示:
2,当 flex-wrap:wrap 时 ————伸缩项目无法容纳时,自动换行 :
3,当 flex-wrap:wrap-reverse 时 ———— 伸缩项目无法容纳时,自动换行,方向和 wrap 相反 :
元素名称 | 说明 |
justify-content:flex-start | 伸缩项目以起始点靠齐 |
justify-content:flex-end | 伸缩项目以结束点靠齐 |
justify-content:center | 伸缩项目以中心点靠齐 |
justify-content:space-between | 伸缩项目平均分布 |
justify-content:space-around | 伸缩项目平均分布,但两端保留一半的空间 |
1,当 justify-content:flex-start 时 ————伸缩项目以起始点靠齐 :
2,当 justify-content:flex-end 时 ———— 伸缩项目以结束点靠齐 :
3, 当 justify-content:center 时 ———— 伸缩项目以中心点靠齐 :
4,当 justify-content:space-between 时 ———— 伸缩项目平均分布 :
5,当 justify-content:space-around 时 ——— 伸缩项目平均分布,但两端保留一半的空间 :
元素名称 | 说明 |
align-itmes:flex-start | 伸缩项目以顶部为基准,清理下部额外空间 |
align-itmes:flex-end | 伸缩项目以底部为基准,清理上部额外空间 |
align-itmes:center | 伸缩项目以中部为基准,平均清理上下部额外空间 |
align-itmes:baseline | 伸缩项目以基线为基准,清理额外的空间 |
align-itmes:stretch | 伸缩项目填充整个容器,默认 |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。